Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Threads synchronizing

Thread view: 
mtp - 04 May 2006 15:47 GMT
Hello,

i have the following problem: in my application, one or more thread must
be able to read some information, all together if they want to. At the
same time, one thread must be able to modify the informations, and the
readers must not gain access when the writer thread is writing.

But one reader must not prevent another reader to access the informations.

Let's say the informations is in the class:

public class Informations {
  /** Write access. */
  public void modify() {
     // some stuff...
  }

  /** Read access. */
  public Object getValue(String key) {
     // some code...
  }
}

What synchronized/flag/else should i put in order to make it work?

TIA
Thomas Hawtin - 04 May 2006 15:03 GMT
> i have the following problem: in my application, one or more thread must
> be able to read some information, all together if they want to. At the
> same time, one thread must be able to modify the informations, and the
> readers must not gain access when the writer thread is writing.

> What synchronized/flag/else should i put in order to make it work?

http://download.java.net/jdk6/docs/api/java/util/concurrent/locks/ReadWriteLock.html

(from 1.5, or use the 1.4 backport)

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

mtp - 04 May 2006 16:22 GMT
Thomas Hawtin a écrit :

>> i have the following problem: in my application, one or more thread
>> must be able to read some information, all together if they want to.
[quoted text clipped - 8 lines]
>
> Tom Hawtin

Thx to both of you.

Where can i get the "backport" (since i work on 1.4 ?).
Thomas Hawtin - 04 May 2006 15:37 GMT
> Thomas Hawtin a écrit :
>>
>> http://download.java.net/jdk6/docs/api/java/util/concurrent/locks/ReadWriteLock.html 
>>
>> (from 1.5, or use the 1.4 backport)

> Thx to both of you.
>
> Where can i get the "backport" (since i work on 1.4 ?).

http://dcl.mathcs.emory.edu/util/backport-util-concurrent/

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Gordon Beaton - 04 May 2006 15:55 GMT
> i have the following problem: in my application, one or more thread
> must be able to read some information, all together if they want to.
> At the same time, one thread must be able to modify the
> informations, and the readers must not gain access when the writer
> thread is writing.

[..]

> What synchronized/flag/else should i put in order to make it work?

It's not so simple to implement this correctly using synchronized, but
it's already been done for you.

See java.util.concurrent.locks.ReadWriteLock.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.