Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4020602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:14:55+00:00 2026-05-20T10:14:55+00:00

I have been messing around with synchronization in Java and it has yet to

  • 0

I have been messing around with synchronization in Java and it has yet to work for me.

I have two Runnable objects that are used to create separate threads, and each object has a handle to a shared ArrayList and a shared Object (for use in synchronized). The first Runnable is always reading tsome instance variable for all of the Objects in the array list, and the second Runnable continuously updates the instance variables for all of the Objects in the array list.

The way I have it setup now, both Runnable objects contain a pointer to an Object that I intended to function as a lock.

Runnable 1:

public void run() {
    if (syncLock == null)
        return;
    synchronized (syncLock) {
        try {
            syncLock.wait();
        } catch (InterruptedException e) {
        }

        for (int i = 0; i < list.size(); i++) {
            drawItem(list.get(i));
        }
        syncLock.notify();
    }
}    

Runnable 2:

public void run() {
    if (syncLock == null)
        return;
    synchronized (syncLock) {
        try {
            syncLock.wait();
        } catch (InterruptedException e) {
        }

        for (int i = 0; i < list.size(); i++) {
            updateItem(list.get(i));
        }
        syncLock.notify();
    }
}    

So technically the first Runnable is always drawing the objects on-screen and the second is calculating the items’ new position based on change in time.

Anything I am missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:14:56+00:00Added an answer on May 20, 2026 at 10:14 am

    It looks like both your threads are going to start and get stuck in wait(), unless you have some other object you aren’t showing there to notify() one of them (just to start them off.) You’d have to be sure that both threads were waiting.

    Alternatively you could change one of them to do their work first, then call notify(), then wait(). Again, you’d have to be sure the other thread was already waiting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been messing around with recursion today. Often a programming technique that is
I have a tricky problem that I've been messing about with for a few
I have been messing around with iTunes COM from python. However, I haven't been
I have been messing around with writing some stored procedures in .NET code with
I have been messing around with Leaks trying to find which function is not
Okay, I have been messing around with different sorting algorithms in Ruby; mainly variations
I've recently taken the plunge into DirectX and have been messing around a little
i am haveing some problems with JSON and arrays. I have been messing around
I've just been messing around with threads in Java to get my head around
I have been messing around with HtmlUnit for a little bit and particularly this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.