Results 1 to 6 of 6
  1. #1
    Droa is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Threads in JSP file

    Hey Java friends

    i've been starting to use Java Servlets and JPS to learn to use it with tomcat... i've am still a beginner, so i made an account on this site, but seems i got deleted?

    well i just made a new account, and got some new questions, i hope people can help me answer..

    as i noticed, a JSP file, gets converted into a temporary httpservlet class, loaded into the tomcat memory.. now my question may seem a part servlet and part jsp, however i got a little confused to where to post it..


    now i want to make a Thread starting up when the servlet-object gets loaded into the memory, to function as a database communicator, so i can compile and sync data in intervals, instead of running for each request.

    i was wondering if i put a new Thread in the
    <%! %> enclosure, if that would do what i wanted?

    short and basic version of what i want.. ofcasue this is only a demo, as it would be pointless to make this in production code.

    DataConnection is the Class i have that manage all data in "this (the jsp file)". that have a while(true) loop, to keep it running

    Java Code:
    <%! 
     public int visitcount = 0; //can be read by DataConnection, as i gets "this"
     Thread t;
    %>
    
    Starts the Thread on the first run of the site.
    <%
      t = new Thread(new DataConnection(this));
      t.start();
    %>

    now i heard that Tomcat makes more of the same object, when max Thread for a object is reached.. so i may hit a wall when i have 4 of the same httpservlet object running.. but i guess i can make some sort of (this objects) visit count. and (all objects) visit count. and count them all up.

    now am i thinking this solution wrong.. or am i on the right path?

    thanks again friends
    Last edited by Droa; 03-03-2012 at 05:43 AM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Threads in JSP file

    I'm trying to see what it is you intend on achieving with this Thread?
    What is it supposed to do?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Droa is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Threads in JSP file

    Quote Originally Posted by Tolls View Post
    I'm trying to see what it is you intend on achieving with this Thread?
    What is it supposed to do?
    My Main problems with my current site, is it uses alot fo network connections to read my forum database, and write new data for it.

    so i want to make a Independents Thread Managing all read/write Operations, that all my servlets have access to use. then instead of writing to the database, i write to a Object i send to the Independent Thread, to manage the new data.. then the Thread will control when the best time to reada/write (Sync) with the database is the best time.. ofcasue the data is lost, if a powerfailer is happening.. however the, if i make the Thread Intelligent enough, it can problerly reduce the damage by alot.


    however i've been thinking if there was an easier way to achive this, by simply make a simple class, i just start in the web.xml would be a better way to make this?

  4. #4
    Droa is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Threads in JSP file


  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Threads in JSP file

    Are you attempting to write your own cache?
    Because that's what it sounds like to me.
    If that's the case then I'd look at some cacheing framework.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Droa is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Threads in JSP file

    thanks for the answer, ill look into this type of frameworks, it just seems so danr usefull, when leading generic page content, from database content :P

Similar Threads

  1. Threads per Connection or Threads per Request
    By Felic in forum New To Java
    Replies: 4
    Last Post: 11-22-2011, 09:15 PM
  2. The right way of using threads
    By N00Bie in forum New To Java
    Replies: 9
    Last Post: 02-20-2011, 04:39 PM
  3. Threads and File I/O
    By tmotse in forum Threads and Synchronization
    Replies: 4
    Last Post: 05-21-2010, 11:53 PM
  4. Threads reading a file and writing
    By akronjava in forum Threads and Synchronization
    Replies: 6
    Last Post: 09-07-2009, 02:52 PM
  5. FileLock and file access from concurrent threads..
    By fxRichard in forum Advanced Java
    Replies: 5
    Last Post: 01-02-2009, 08:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •