Waking up sleeping Java applications

W

Wes Harrison

Why is it that when a Java application (esp. Swing) running under Windows
2000 has been minimized for a while, it needs time to "wake up"? In my
experience, some of these apps can take up to 30 seconds on my PIII 500
machine until they have refreshed their screen and will accept input. The
longer they sleep, the longer it takes to wake up in general and while it's
waking up there is a lot of disk activity.

What's going on during this time? I don't think it's garbage collection.

This has happened on every machine I have used Java on so I guess it's a
feature but I don't think Java will succeed on the desktop until it has been
resolved.

Wes
 
M

Mark Thornton

Wes said:
Why is it that when a Java application (esp. Swing) running under Windows
2000 has been minimized for a while, it needs time to "wake up"? In my
experience, some of these apps can take up to 30 seconds on my PIII 500
machine until they have refreshed their screen and will accept input. The
longer they sleep, the longer it takes to wake up in general and while it's
waking up there is a lot of disk activity.

What's going on during this time? I don't think it's garbage collection.

This has happened on every machine I have used Java on so I guess it's a
feature but I don't think Java will succeed on the desktop until it has been
resolved.

Wes

It is a side effect of memory use --- it happens on many applications
that use a lot of memory. The time is taken by the OS paging back in to
memory pages that are needed to respond to your action.

Mark Thornton
 
W

Wes Harrison

It is a side effect of memory use --- it happens on many applications
that use a lot of memory. The time is taken by the OS paging back in to
memory pages that are needed to respond to your action.

But MemTurbo is reporting over 400MB of free RAM (out of a total of 768MB)
so why would Windows need to do any paging? And I haven't noticed this with
non-Java applications.

Wes
 
C

Chris Smith

Wes said:
So that's it? No one has a better answer to my question?

Not without seeing an example, no. I've never seen the symptoms you're
describing, and I can't find a reference to them anywhere. Which
applications are we talking about? What operating system and version?
Can you post some code that acts this way?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

What's going on during this time? I don't think it's garbage collection.

Your OS is swapping the entire app out. To bring it back it has to
read it all back into RAM. If you had more ram or a faster hard disk
you would not see that.
 
N

nos

there must be something more than just having
the app swapped out
normally swapping in is faster than a complete
startup and startup is only 5 seconds not 30 or more
 
W

Wes Harrison

Your OS is swapping the entire app out. To bring it back it has to
read it all back into RAM. If you had more ram or a faster hard disk
you would not see that.

But as I said in the other post, I have 768MB of RAM of which at least 400MB
is free at the time. Why would Windows be swapping the entire app out under
these circumstances? I am using Java 1.4.2 on Windows 2000 and example apps
are NetBeans and MagicDraw.

Wes
 
M

Michael Borgwardt

Wes said:
But as I said in the other post, I have 768MB of RAM of which at least 400MB
is free at the time. Why would Windows be swapping the entire app out under
these circumstances?

Because it's trying to be "smart". Windows assumes that a minimized app
is "inactive" and preemptively swaps it out so that there will be less delay
when another app needs the RAM.
 
W

Wes Harrison

Because it's trying to be "smart". Windows assumes that a minimized app
is "inactive" and preemptively swaps it out so that there will be less delay
when another app needs the RAM.

But this only seems to happen for Java programs in my experience. A native
Windows app gets swapped back in almost instantaneously in most cases.

Wes
 
R

Roedy Green

Why would Windows be swapping the entire app out under
these circumstances?

check the task manager. You will be amazed how many tasks are running
you did not explicitly start. Never underestimate Windows penchant to
do something stupid. I was written by large teams of inexperienced
programmers.
 
W

Wes Harrison

check the task manager. You will be amazed how many tasks are running
you did not explicitly start. Never underestimate Windows penchant to
do something stupid. I was written by large teams of inexperienced
programmers.

Why isn't anyone prepared to acknowledge that Java IS the problem? It only
happens with Java apps and happens with all the large Swing apps I run.
Perhaps I asked this question in the wrong NG.

Wes
 
A

Andrew Thompson

.....
Why isn't anyone prepared to acknowledge that Java IS the problem? It only
happens with Java apps and happens with all the large Swing apps I run.

How do you percieve the performance of those same
large Swing apps under Linux, Mac OS X, Solaris..,
do you still suffer the same problems with Java under
_those_ systems, or could it perhaps be that..
Windows IS the problem?
 
R

Roedy Green

Why isn't anyone prepared to acknowledge that Java IS the problem? It only
happens with Java apps and happens with all the large Swing apps I run.
Perhaps I asked this question in the wrong NG.

Because Java in not in charge of swapping to disk. Uncle Bill is, and
you know how much he loves Java.
 
B

Ben Jessel

I would hazard a guess that windows always pages it out of memory when
you minimize it. However, the reason that C++ ms programs etc dont
have this problem is that they don't have virtual machine code and
state to restore. I'm guessing that javaw, java.exe and all the .dll's
that it relies on are pretty big. Not only that, the virtual machine
has to be loaded, the code that you are running on it is then stored.
With java you are running a program that is itself running a program.
I guess with MFC and Microsoft programs, the runtime environment is
part of the Microsoft Windows environment.

Also, could it be that the classloader refreshes all the classes once
an app becomes re-activated?

I think roedy even suggests himself on his site an idea for a project
where Java dll's are held in memory to enable faster app startup.

What is the time that it takes to initially load up an application
in terms of the time taken to re-activate the app?

Just a couple of thoughts...
 
C

Chris Smith

Wes said:
Why isn't anyone prepared to acknowledge that Java IS the problem? It only
happens with Java apps and happens with all the large Swing apps I run.
Perhaps I asked this question in the wrong NG.

Basically Wes, as far as I can tell, no one else is seeing the symptoms
you are describing. If we were, we might possibly be able to explain,
because we could look into the problem further.

As it is, you're getting a lot of people jumping at their pet peeves.
Those who dislike Windows are going to assume that Windows memory
management is the problem. You obviously dislike Java and are going to
assume that Java is the problem. Both of you may be right, or there may
be some combination of the two that just interacts badly (for example,
if a Java application has been completely swapped out of memory, and
then needs to perform a garbage collection, then a lot of paging will be
needed prior to completing the collection).

Fact is, no one knows anything, and everyone is just about as likely to
be wrong as anyone else.... but you're right; if you wanted someone to
validate your feeling that it must be all Java's fault, you probably
picked the wrong newsgroup.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Smith

Ben said:
I would hazard a guess that windows always pages it out of memory when
you minimize it.

That seems to be common knowledge... At the very least, it
substantially reduces the working set size for the process, causing much
of the process to be swapped out to disk.
However, the reason that C++ ms programs etc dont
have this problem is that they don't have virtual machine code and
state to restore.

I doubt that's really an issue, actually. The larger virtual machine
subsystems, like the JIT compiler, are unlikely to be needed when
returning to a long-running Java application. As I just said in another
response, I suspect it's a degenerate relationship between garbage
collection and Windows memory management.

Another artifact of Windows memory management is that instead of using a
straight LRU policy for paging, Windows tries to be fair; it keeps track
of a "working set size" for any given application, and only very
reluctantly adds memory to that working set size if the application
establishes a pattern of swapping. That's a really bad idea when an
application is running a large garbage collection and is mostly swapped
out. If a substantial portion of memory accesses by the garbage
collector are paging, then gc can take 50 to 100 times longer than it
would if the VM subsystem would cooperate. I suspect the VM subsystem
in Windows is optimized around applications with manual memory
management, and no one ever considered how to avoid a pathological case
with garbage collection.

Nevertheless, I've still never actually seen the described symptoms.
Also, could it be that the classloader refreshes all the classes once
an app becomes re-activated?

No. That's definitely not the case.
I think roedy even suggests himself on his site an idea for a project
where Java dll's are held in memory to enable faster app startup.

Indeed. Back when I still had some time, a few others and I fleshed out
the idea, and documented our plans at http://chives.sunsite.dk/. Then,
of course, we all got too busy before we could complete the test
implementation. Word on the street is that Sun and Apple are
collaborating on a similar approach, but there's no committed release
schedule.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
N

nos

Here is some new data for you.
--------------------------------
I have a java 1.4.2 (SUN SDK) application that has two windows
running on a laptop with Win XP Pro. Celeron 2.0 GHz, 256 K memory.
One window is a bunch of buttons on each of 8 tabbed panes.
The other window looks at parameters that are set by the
button clicks and displays a 3-D image using simple AWT DrawLine()
and DrawString(). When it is running I bring up the "Windows Task Manager"
and look at the process list. The program is using more than 97 percent of
the cpu
and it uses about (ballpark) 22,000 K
The image is being drawn as fast as it can go.
These numbers/behavior are about the same for javaw.exe and for java.exe.

Now if I minimize both windows via the dashed button in the upper right
of the window, the cpu stays above 97 percent and the memory usage
stays around 20,000 K according to the windows task manager.

Now when I click the task bar icon for each window it jumps up into
action in a fraction of a second.
 
M

Michael Borgwardt

nos said:
Now if I minimize both windows via the dashed button in the upper right
of the window, the cpu stays above 97 percent and the memory usage
stays around 20,000 K according to the windows task manager.

Now when I click the task bar icon for each window it jumps up into
action in a fraction of a second.

No surprise there; of course a process can't be swapped out muc while it's
busily working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top