• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New threads in J2EE application

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic