Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2007, 02:00 AM
Member
 
Join Date: Jul 2007
Posts: 41
fred is on a distinguished road
question about Multi threading in Java
how can I avoid race condition and deadlocks in a java multi threading environment where all the threads share a common resource.
thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 03:55 AM
Member
 
Join Date: Jul 2007
Posts: 44
simon is on a distinguished road
If you have only one resource that must be locked deadlocks can not be a problem, since deadlocking occurs only when thread A has acquired lock 1, thread B has acquired lock 2 and A needs to acquire lock 2 and B needs to acquire lock 1.

A race condition can always occur if the shared resource is mutable and not thread safe. In a simple case making the method which sets the value of the shared resource (and this method is part of the resource itself) synchronized should do the trick.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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
Question mark colon operator question orchid Advanced Java 4 11-12-2008 10:08 AM
Java threading Eranga Advanced Java 2 03-13-2008 07:30 AM
Threading prob.. banie Java Applets 0 02-05-2008 08:30 AM
Java Pacman question whdbstjr90 New To Java 0 12-12-2007 01:28 AM
Explanation bout threading and concurrency? cruxblack New To Java 1 08-10-2007 12:33 PM


All times are GMT +3. The time now is 04:45 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org