Go Back   Java Programming Forums > Java Standard Edition Programming Help > Threads


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-01-2010, 10:45 AM
Junior Member
 

Join Date: Jan 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
adamruss is on a distinguished road
Default sync two diffrent kind of threads?

hello, hopefully i will be able to explain this clearly..

i have an static object named:
Java Code
public static Document dataFileXml;
and, i have two kind of threads running:
Java Code
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!



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 11-01-2010, 12:59 AM
copeg's Avatar
Moderator
 
9 Highscores

Join Date: Oct 2009
Posts: 570
Thanks: 7
Thanked 131 Times in 125 Posts
copeg will become famous soon enoughcopeg will become famous soon enough

I'm feeling Sleepy
Default Re: sync two diffrent kind of threads?

Flank any changes to your dataFileXml object using synchronized

Java Code
synchronized (dataFileXml){
     ///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.
Reply With Quote
Reply

Tags
thread monitor syncronize

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Questions About Threads neo_2010 Threads 4 15-03-2010 01:04 PM
threads in gui urosz AWT / Java Swing 1 03-11-2009 09:20 PM
What kind of List? Sterzerkmode Java Theory & Questions 1 07-05-2009 09:48 AM
[SOLVED] Threads and variable Koren3 Threads 3 21-04-2009 11:28 AM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:57 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.