Skip to main content

How can javaw take over XP?

8 replies [Last post]
jay_levitt
Offline
Joined: 2005-09-10

I'm a Java newbie, and in working with Eclipse, I've noticed that CPU-intensive operations (not to mention tight loops) can freeze Windows XP up solid - you can't even get a task manager up. This is with JRE1.5.0_04.

I've searched around for discussions, and found mentions of many popular Java apps displaying that behavior - Eclipse, Azureus, etc. The usual response is "you should fix that infinite loop in your code", but that doesn't address the core issue - how, exactly, is javaw able to grab such hold of a preemptive-multitasking machine? Isn't it a user-level app?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ran7377
Offline
Joined: 2005-10-01

I also have a similar problem. I run XP SP2 with dual Pentium 4, 3.2 GHz processors and 2.0 GB of RAM. My sound card is Soundblaster Audigy 2zS and within 10 minutes of playing a POGO game my sound goes (however I can play music) then within a few minutes my system freezes and there is absolutely no movement whatsoever from the system and I cannot do anything but a hard re-boot. It also started doing the same thing using Adobe, Word, Excel, Corel and AutoCAD(losing all data). I disabled everything and tried a process of elimination and concluded it was my sound card although the problem stopped and Creative could not find a fault. Tonight I went to play a game that would not run with Microsoft and enabled Sun and within 10 minutes my sound died. I changed back to Microsoft and have noew uninstalled the Sun. Is there not a fix out there for this?

pepijnve
Offline
Joined: 2003-06-10

I saw a related discussion on the Java Games fourms:
http://192.18.37.44/forums/index.php?topic=10269.msg82032#msg82032
which eventually pointed to this bug
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5101898

jay_levitt
Offline
Joined: 2005-09-10

Ah HAH!! That bug description, workaround and fix sound like they describe this problem perfectly. I will try adding that to my Java startup scripts.

Is there some %JAVAOPTS%-type variable or .javarc file where I can store global options for the JVM?

sdo
Offline
Joined: 2005-05-23

javaw is a user-level app, and it's displaying the same behavior that many user-level apps display on XP (and other versions of windows).

The Windows thread scheduler is pre-emptive and multi-tasking, but it's designed to give precedence to whatever application is running in the window that has the focus. If that (application) window has one or more threads with tight loops, then the Windows OS is happy to give those threads priority -- to the point where other threads in the system "starve" for CPU time. This is especially true if you give the java threads a priority above 7 (Thread.NORM_PRIORITY + 2).

Another common cause of symptoms like is not enough physical memory on the machine -- Windows will begin using its virtual memory, but depending on the type of disk you have, the paging can be very time-consuming. If you notice lots of disk activity during the times when XP seems frozen, then you might want to consider getting more physical memory.

Scott

jay_levitt
Offline
Joined: 2005-09-10

That's not what I'm seeing, though. Oddly enough, I'm usually able to switch other apps to the foreground, but java still won't (usually) yield enough CPU for them to refresh their portion of the display.

Even if the Java threads have high priority, if javaw itself has normal priority (which it does), shouldn't they still end up getting shoved off the processor? I've never seen any other app exhibit this behavior; yes, threads can starve other threads, but I've never seen them starve other apps since 32-bit apps came about. Even the following C program:

while (1) {;}

maxes out the CPU at 85-95%; it can take a few seconds to pull up a task manager, but once it does come up, it updates every second like normal.

Physical memory isn't the problem either - I have 2GB physical, and never, ever page.

There's something different about what Java does.

alexlamsl
Offline
Joined: 2004-09-02

Yes, an infinite loop of a "normal" priority process in XP should never take up much of CPU time.

Except when the it causes the system to page or accessing some other "critical" services within the loop, network / physical storage / BIOS, for instance.

I do cast my slight doubt over your claim that a 2GB RAM machine never ever pages; as far as I know even the 4GB RAM machines I have used to develop both .NET and Java applications will need to page once in a while under normal usages. (for applications with complexity comparable to an IDE, that is)

jay_levitt
Offline
Joined: 2005-09-10

Oh, I'm sure I *could* get it to page, but I'm not - my peak commit charge is ~1140MB. I'm actually using Eclipse to develop Rails apps, which use many fewer source files than .NET and Java, and no object files, so that probably keeps the memory down - right now I'm at ~200 LOC.

Eclipse and javaw are taking up just 75M; most of the RAM is auxiliary desktop stuff like Firefox, Thunderbird, Acrobat, Outlook, TopDesk, etc. I guess I'm just a lightweight!

Sooo.. how can I troubleshoot what it is about Java that's managing to not only take up 100% CPU, but starve other processes in the, er, process?

alexlamsl
Offline
Joined: 2004-09-02

I can see your point there.

I guess in order for us to continue our discussions, it might just be helpful to describe the nature of the infinite loop that you've got which managed to "starve" other processes. ;)