• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with timer and imagefecter threads

 
Am Kat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing one applet having few images inside it. I am getting those images throgh URLs. On first display, images are rendered correctly but whenever I do refresh an applet, the images are grayed out and I see two threads suspended in my debug window. One is TimerQueue and another is ImageFetcher. Both of these classes are implemented in runtime jar rt.jar. The funny thing is if I set the breakpoint on the method which return the image url and run applet, it could render the images correctly. This because it Imagefetcher runtime thread gets some amount of delay.

I think there is some problem with the way these threads are communicating with eachother. What should I do in order to have proper communication between these two. I couldn't invoke yeild since I both of these threads are implemented by JVM. Is there any other way?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

I don't think your diagnosis is correct. If you can post the parts of your code that deal with the images, perhaps we can help figure out the problem.
 
Am Kat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are correct, problem is not exactly the same what I stated earlier. It has nothing to do with the TimerQueue thread but ImageFetcher thread of rt.jar is behaving arbitrarily. Following is the more concrete diagnosis:

I've one method setIcon(String iconURL). In the applet I've a graph. In the graph, I am displaying multiple nodes. Every node has 2 images. The setIcon(String iconURL) method is invoked as many times it need to display image. e.g. If I've 25 nodes, the method is invoked 25 * 2 = 50 times. During the debugging, when I refresh the graph I saw few imageFetcher threads suspended. One solid hint here is the

no. of suspended threads = no. of icons not displayed.

When I tried to have a look at imageFetcher class ( using decompilation technique:-) ), I found that there are few synchronized blocks on fetcherinfo objects. (I am not sure what exactly is that). So this could be one possible cause of problem. May be the suspended threads are not releasing fetcherinfo locks and next time (i mean after refresh), it is not able to execute those blocks.

But..........

Second thought which came to my mind is that it could be a problem of race condition and that's why it works correctly when I add a breakpoint and indirectly add delay in the current thread. Hence, as a workaround I tried adding Thread.sleep() call and IT WORKED. But I cannot afford to have sleep in the method which would be invoked 50 times on many events. It drastically decreases my applet performance.

Now, I am confused and trying to investigate more on this. Could you please please help me out?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you caching the Image(Icon) objects, or re-fetching 50 images every time? You need to cache them so they only need to be downloaded once.
 
Am Kat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are cached. I could see them in the JRE plugin cached files.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I mean once you create a Java "Image" or "ImageIcon", do you keep it, or do you create new ones every time you need them? You need to keep those images, rather than re-reading the files constantly.
 
Am Kat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, I don't have control over that code. I am using third party jars (ilog - Jviews) for displaying graph. The setIcon() method I described earlier is been called from the ilog code. I could only check if the correct URL is passed ot not. What could be the reason when it works correctly after adding Thread.sleep(1000) call before invoking setIcon(). In the JRE traces, it not even tries to load the image. Otherwise, on first display it shows traces like...

network: Connecting http://waveplb:9999/bqz_R17_epm/file/resources/graphic/icons/normal/I_ENOVIA_EPMLoopActivity.gif with proxy=DIRECT
network: Connecting http://waveplb:9999/bqz_R17_epm/file/resources/graphic/icons/normal/I_ENOVIA_EPMLoopActivity.gif with cookie "JSESSIONID=00002MnEEwibieyGTr-SIb14H60:-1"
basic: Loading http://waveplb:9999/bqz_R17_epm/file/resources/graphic/icons/normal/I_ENOVIA_EPMLoopActivity.gif from cache


for every image in the graph.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm. You probably should have brought up the third-party library thing in the first place! Is there any way to get support for jviews? It sounds like it could be their problem, then.
 
Am Kat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I tried to override their implementation of setIcon() method and doing nothing special but a super call. The same jars are working for my other applets. So what so special about this applet? The difference is I've more no. of images in this applet. My analysis from last few hours I concluded that it is surely a problem of synchronization between EventQueue and imageFetcher threads. To support this statement have a look at these links from Sun's bug database.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4339995

Also, the similar topics are discussed in following bug ids. (just replace the last bug_id parameter value in URL)
4837639
4034102
4480705
4179072

Per the explaination given by Sun, they've already fixed this problem in pos 1.4.1 releases by modifying startingAnimation() method.

The new startingAnimation() is:
static void startingAnimation()
{
FetcherInfo fetcherinfo = FetcherInfo.getFetcherInfo();
Thread thread = Thread.currentThread();
Vector vector = fetcherinfo.waitList;
JVM INSTR monitorenter ;
int i = 0;
_L2:
if(i >= fetcherinfo.fetchers.length)
break MISSING_BLOCK_LABEL_103;
if(fetcherinfo.fetchers[i] != thread)
break MISSING_BLOCK_LABEL_97;
fetcherinfo.fetchers[i] = null;
fetcherinfo.numFetchers--;
thread.setName((new StringBuilder()).append("Image Animator ").append(i).toString());
if(fetcherinfo.waitList.size() > fetcherinfo.numWaiting)
createFetchers(fetcherinfo);
return;
i++;
if(true) goto _L2; else goto _L1
_L1:
break MISSING_BLOCK_LABEL_115;
Exception exception;
exception;
throw exception;
thread.setPriority(2);
thread.setName("Image Animator");
return;
}

Another bug explanation is, imageFetcher thread is starved due to timerqueue thread. The workaround suggested their is to set low priorty on timerQueue thread. Is it possible to change the priorty of such JVM threads in my code? If yes, how? I only have one hookup when the event thread is created i.e. actionPerformed() from ActionListner interface.

Though, I understood many things from this, I couldn't find any solution or atleast any work around. Can you please help me? Also, somewhere they suggested to have a sleep in imageFetcher thread and that's why my yesterday's workaround to add sleep was working correctly.


I am still pretty confused. Please be assure that there is nothing wrong with the 3rd party jar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!