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 9065683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:34:00+00:00 2026-06-16T16:34:00+00:00

I am new to Java, and have come across a problem when trying to

  • 0

I am new to Java, and have come across a problem when trying to implement a simple game.
The premise of the game currently is, a timer is used to add a car, and also more frequently to update the movement of the car. A car can be selected by touch, and directed by drawing it’s path. The update function will move the car along the path.

Now, the game crashes with an IndexOutOfBoundsException, and I am almost certain this is because occasionally, when a car is reselected, the current path is wiped and it allows a new path to be drawn. The path is stored as a LinkedList, and cleared when the car is touched.

I imagine if the path is cleared via a touch event, whilst the timer thread is updating the cars movement along the path, this is where the error occurs (There are also similar other issues that could arise with two threads accessing this one list.

My question, in Java, what would be the best way of dealing with this? Are there specific types of lists I should be using rather than LinkedList, or are there objects such as a Mutex in c++, where I can protect this list whilst working with it?

  • 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-06-16T16:34:01+00:00Added an answer on June 16, 2026 at 4:34 pm

    In Java, this is usually accomplished using synchronization

    A small example might look something like this:

    LinkedList list = //Get/build your list
    
    public void doStuffToList()
    {
        synchronized(list)
        {
            //Do things to the list
        }
    }
    
    public void clearList()
    {
        synchronized(list)
        {
            list.clear();
        }
    }
    

    This code won’t let the clear operation be performed if there’s another thread currently operating on the list at that time. Note that this will cause blocking, so be careful for deadlocks.

    Alternatively, if your List is a class that you’ve built yourself, it probably makes sense to make the data structure thread safe itself:

    public class SynchroLinkedList
    {
        //Implementation details
    
        public synchronized void doThingsToList()
        {
            //Implementation
        }
    
        public synchronized void clearList()
        {
            //Implementation
        }
    }
    

    These two approaches would effectively work the same way, but with the second one your thread safety is abstracted into the datatype, which is nice because you don’t have to worry about thread safety all over the place when you’re using the list.

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

Sidebar

Related Questions

I'm fairly new to java and have come across a problem. My task is
I have come across Java code in this form for the first time: object.methodA(new
I am new to java and I have some problem on Casting. I have
I have come across a strange behavior of Java that seems like a bug.
I have come across a problem and am not sure which would be the
Ive come across a nice problem recently, I have a Map LinkedHashMap<String, List<MyCustomObject>> I
I've come across a problem that I have searched and searched for a solution
I'm working in Java and have come across an incredibly odd error. I have
I'm trying to re-write a java android app into monodroid, however I have come
I am relatively new to working with Java and have come from a C/C++

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.