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 atomic block of code? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "atomic block of code?" Watch "atomic block of code?" New topic
Author

atomic block of code?

david zhang
Greenhorn

Joined: Oct 12, 2003
Posts: 27
Hi,

I am coding an application. It has a thread that can be requested to stop any time during its execution.
Inside the thread, there are a few lines of code that should be executed all or none. In another word,
if the thread runs in the middle of this block, then outside interrupt/stop request should not stop the thread
before the block finishes. How can this be accomplished? This block of code has nothing to do with database write.

Thanks,
David
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24039
    
  13

Depends on how the "request to stop" is being made. If you're using the deprecated stop() method, then I don't believe there's anything you can do. If you're using interrupt() or a "stop flag" of your own devising, then you simply need to not check these things during the block of statements.


[Jess in Action][AskingGoodQuestions]
david zhang
Greenhorn

Joined: Oct 12, 2003
Posts: 27
Ernest,

Thanks for your advice. I will try.

David
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: atomic block of code?
 
Similar Threads
synchronized(this)
Finally block
directly stopping a thread
Using interrupt() to stop a thread
true false question for Thread