Results 1 to 2 of 2
  1. #1
    fred is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default 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.

  2. #2
    simon is offline Member
    Join Date
    Jul 2007
    Rep Power


    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.

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. Java threading
    By Eranga in forum Advanced Java
    Replies: 2
    Last Post: 03-13-2008, 05:30 AM
  3. Threading prob..
    By banie in forum Java Applets
    Replies: 0
    Last Post: 02-05-2008, 06:30 AM
  4. Java Pacman question
    By whdbstjr90 in forum New To Java
    Replies: 0
    Last Post: 12-11-2007, 11:28 PM
  5. Explanation bout threading and concurrency?
    By cruxblack in forum New To Java
    Replies: 1
    Last Post: 08-10-2007, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts