Thread Exchange Failure

I ran into recent lag spikes in a game I was developing. This is consistent, happening at about the same time. Using the javaualvm java profiler, I found that this happens at the same time when some thread seems to be restarting or something (AWT-EventQueue-0):

Image of Thread changing channels

Other than that, there is no apparent reason, not heap usage, processor usage, memory space, or methods. When drawing my array of objects, a ConcurrentModificationException sometimes occurs, but this should only happen with a significant lag, and my game is unlikely to be intense.

I don’t remember making any recent changes to the project, however recently I did the following:

  • Updated java to latest version
  • The latest version of JDK7 has been downloaded (although it is not used in this project)
  • Fixed bug with eclipse resulting from the installation of JDK7 (256 m remote limit in eclipse.ini)

I am running Eclipse Indigo-service-1 on 32-bit XP. My processors are almost never used.

+4
source share
1 answer

It sounds like you are doing too much on Dispatch Event (EDT). AWT-Event-Queue-0 looks like an EDT. Also, your last comment says

... it seems that the lag only happens when I draw my game panel first on the image, and not directly on the component.

You will need to push some of your calculations to other threads, and it seems that drawing the playing field is a good choice for this. In addition, any AI that you have.

Keyboard and mouse handlers run on EDT, and graphics updates are also needed. But you can pre-render the image (as you are doing now) outside of EDT. And you can send keyboard and mouse events to another thread through BlockingQueue.

Another thing you could do is to cancel the refresh rate of your game from the frame refresh rate.

But without any details, I cannot give more advice.

Update : (just read your bit about ConcurrentModificationException )

This can be caused in two different ways:

  • You are updating the collection (for example, ArrayList) in a different thread from the one in which you are reading it; or
  • you repeat this assembly and update it in a loop.

Point 2 is easy to fix; but I am afraid that I cannot teach the safety of flows in such a short space.

+5
source

All Articles