File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Thread execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread execution" Watch "Thread execution" New topic

Thread execution

Anuj Joshi

Joined: Feb 05, 2009
Posts: 22

I have written a code in a thread & need to execute this code completely & then it should execute code outside the thread.

what I want the execution of the below code(i.e. code-2) should be executed after thread. how can I do this??

Please reply soon
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Please be careful which forum you post in. I am sure Rob and Maneesh won't mind if I move this thread.
Your code is very difficult to read; you would do better to post an SSCCE.
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
You can use java.util.concurrent.CountDownLatch

SCJP 1.4
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

If what you are asking is the ability to execute a code after a thread has finished execution, all you need is a join

apigee, a better way to API!
Doua Beri
Ranch Hand

Joined: Sep 24, 2009
Posts: 60
I'm not sure if I understand the question but if you want a certain code to be executed after a certain thread finish executing his task you should use a ThreadPoolExecutor and rewrite the afterExecute method . hope this helps
I agree. Here's the link:
subject: Thread execution
It's not a secret anymore!