• Post Reply Bookmark Topic Watch Topic
  • New Topic

New threads in J2EE application  RSS feed

 
Mike Nason
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have the application that consists of EAR + web module (war) inside, deployed on Glassfish.
I need multiple threads inside war, so I used new Thread().start() to create them.
Some guys said that it is not correct to create custom threads inside j2ee container, so I need to use other tools provided by j2ee container to do this.

Actually I have read j2ee5 specification and didn't notice anything special concerning new threads there, except EJB container, inside of which the creation of new threads are not allowed.

It is ok to create the new threads inside glassfish web module with thread.start()?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The containers provided by an application server are there to manage threads for you. There is nothing to prohibit you starting your own threads in the Servlet container, though for most I can't really think of a good reason to start a thread from a Servlet itself. I suppose you just have to think through what you are trying to achieve and make sure you are not doing something that container already does for you. What do your threads do and where are they started?
 
Mike Nason
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have application that handles http request then push http request back as a response.
The load is very hight, so I have a HttpRequestThread to perform http request for each http request handled by my application.
That thread has blocking queue of request that need to be posted, so not to make servlet thread( the thread that handles original incoming request) waiting I put httpPost task to blocking queue, so the post task will be handled in other thread...

The other thing is that we need to check database from time to time so I need java.util.Timer there (which is also the thread)

So on...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Nason wrote:We have application that handles http request then push http request back as a response.
The load is very hight, so I have a HttpRequestThread to perform http request for each http request handled by my application.
That thread has blocking queue of request that need to be posted, so not to make servlet thread( the thread that handles original incoming request) waiting I put httpPost task to blocking queue, so the post task will be handled in other thread...

This sounds like you are maybe hand rolling what could be achieved by deploying your Servlets in multiple Servlet containers behind a load balancer are you not? Wouldn't this be easier? If you want to do anything with the result of your thread in the context of the same request you are going to have to block anyway, or figure out some mechanism to return an asynchronous response to the client.


The other thing is that we need to check database from time to time so I need java.util.Timer there (which is also the thread)

This is fine in a Servlet container.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!