Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Threaded Object(s)

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Threaded Object(s)

    Hi

    Hoping someone can help with this

    Scenario : I have threaded objects on a wait method when the condition becomes true 3 threads are active.

    I want to let 2 or less through my condition but the other runnable/running thread disappears and I lose it.

    Any advice on how I might achieve this

    Thanks for looking


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,301
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Threaded Object(s)

    What have you tried? Where are you stuck? Where's your SSCCE?

    Recommended reading: Lesson: Concurrency (The Java™ Tutorials > Essential Classes)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Threaded Object(s)

    Hi Kevin

    synchronized void doSomething(Object x)
    {
    if(x.doThis()!=this.doThat())
    {
    try
    {
    wait();
    }
    catch(InterruptedException anException)
    {
    System.out.print("Error" + anException);
    }
    }
    if statement goes here (I think)

    The Threads are held in a List collection

    This is the the condition I am trying to achieve :

    if(theList<3 then do something) .........2 threads go through but one is let through the condition and it is lost

    (3 threads will always wake at the same time)
    In my other sychronized method I have a notify all to wak the threads up.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Threaded Object(s)

    Can you make a small complete program the compiles, executes and shows the problem.
    Thread problems can be complex and require more than a few lines of code to resolve.
    Be sure to wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: July 24th, 2011, 06:13 AM
  2. Multi-Threaded Chat Server
    By TopdeK in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 7th, 2011, 10:12 AM
  3. Creating a threaded applet
    By mjpam in forum Java Applets
    Replies: 22
    Last Post: August 11th, 2010, 06:37 PM
  4. Threaded algorithms
    By TerTer in forum Algorithms & Recursion
    Replies: 0
    Last Post: April 20th, 2010, 08:34 AM
  5. Replies: 1
    Last Post: October 19th, 2009, 11:53 PM