File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Another synchronized block question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Another synchronized block question" Watch "Another synchronized block question" New topic
Author

Another synchronized block question

Bindu Dharmavaram
Greenhorn

Joined: May 23, 2001
Posts: 9
Hi,
I have the following code.

In the above code, I started a thread to wait for sometime before it shuts down this process, by that time, returning the "shutdown success" String.
Seems like the thread start is happening before the return line. So, the system.exit(0) is happening before I can send out the return value.
My idea of having a synchronized block in run method that object has to perform the return before running the synchronized block in the run method of the kill thread. Does not seem to help.
Any suggestions as to how I can send the return value before exiting the program ?
Thanks
-Bindu
[Added CODE tags - PdH]
[ February 08, 2002: Message edited by: Peter den Haan ]
Bindu Dharmavaram
Greenhorn

Joined: May 23, 2001
Posts: 9
To add on,
Actually, the method shutdown is synchronized too.
So, by having another synchronized block within run method of the thread should complete the return statement, and then run the thread inside the inner block.
The process, which is listening on the return variable from this method is timing out not able to receive that return string. Hence, I think that the System.exit(0) in the run method is somehow executed before the return statement.
Is this normal behavior ?
 
 
subject: Another synchronized block question
 
Threads others viewed
is it possible that a parent thread dies before the child ?
synch in threads
Can you still access an unsnychronized method even when there is a lock on the object?
JQ+ Mock - Threads - Question ID: 988383703406
Object locking in threads(maha anna pls help).
developer file tools