sync two diffrent kind of threads?
hello, hopefully i will be able to explain this clearly.. :)
i have an static object named:
and, i have two kind of threads running:
public static Document dataFileXml;
final class HttpRequest implements Runnable // (could be none, could be many)
public class ReminderSender implements Runnable // (only one thread running all the time)
- Both of them have functions that read and write to "dataFileXml".
- i am familiar with sync,wait,notifyall method for shared memory between multiple threads of the same kind - but does this work with two kinds of threads?
- anyway - does anyone have a good suggestion how to make sure only one thread will have access to dataFileXml and the rest will have to wait for their turn?
Thanks in advanced!
Re: sync two diffrent kind of threads?
Flank any changes to your dataFileXml object using synchronized
///make changes to dataFileXml
This will cause a thread to lock the object and force other threads to wait for it to unlock before any changes can be made. A thread is a thread, so whether or not the runnable interface is implemented between objects, they are all just threads.