File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Do I need to do a Thread.join() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Do I need to do a Thread.join() ?" Watch "Do I need to do a Thread.join() ?" New topic

Do I need to do a Thread.join() ?

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 782

I have a Servlet which instantiates a Service class and invokes a method (which I'll call doStuff).

Since the method sendToRemoteServer takes a long time, can I safely:
  • run it in a Thread ?
  • If yes to the previous question, do I need to join this Thread ? i.e. do I need to call thread.join() whereby thread is the reference to the Thread that executes "sendToRemoteServer".

  • Thanks all


    Ove Lindström
    Ranch Hand

    Joined: Mar 10, 2008
    Posts: 326

    I would implement the print-job as a Task and then have an Excecutor-object run it. If you need to have some sort of callback when it is done, you can use a Semaphore or a CountDownLatch.
    I agree. Here's the link:
    subject: Do I need to do a Thread.join() ?
    It's not a secret anymore!