<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4616.200" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>I did run into a 
very similar problem myself&nbsp;when writing&nbsp;my VTK-based Java 
application&nbsp;and was able to find a </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>solution to 
</FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial size=2>solve 
</FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial size=2>my 
problem.&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>Basically, as you 
have found out, the main reason that your idea doesn't work is that&nbsp;VTK is 
not thread safe.</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>One way that you can 
try is, once you enter the method associated with A, you essentially take over 
the</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>system event queue. 
Somewhere inside the infinite loop, you check&nbsp;the system event queue to see 
if button </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>B has been 
pressed.&nbsp;For my </FONT></SPAN><SPAN class=301013917-01042002><FONT 
face=Arial size=2>application, this strategy works well with JDK1.3.1, but 
somehow&nbsp;doesn't </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>work 
with&nbsp;JDK1.4.0. It seems&nbsp;</FONT></SPAN><SPAN 
class=301013917-01042002><FONT face=Arial size=2>to me that the system event 
queue&nbsp;is not implemented correctly in JDK1.4.0.</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>Another way to solve 
your problem&nbsp;is to get rid of the infinite loop in&nbsp;the method 
associated with A. When</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>button&nbsp;A is 
pressed, what you do is&nbsp;that you create and start a thread, 
say&nbsp;MyThread. After that, method A </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>executes 
</FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial size=2>ONLY ONCE 
the code that you have in the original infinite loop. Now, when button B is 
pressed, </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial 
size=2>you&nbsp;</FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial 
size=2>basically&nbsp;set some&nbsp;boolean flag in your&nbsp;main application. 
The key&nbsp;idea is&nbsp;how you design MyThread. </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>What 
</FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial 
size=2>I&nbsp;would do&nbsp;is let the thread sleep for approximately the time 
which&nbsp;the code in the original infinite loop </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>takes 
</FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial size=2>to execute. 
When&nbsp;the thread&nbsp;wakes up, it&nbsp;takes one of the following two 
choices. If the boolean flag </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>in the main 
application has </FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial 
size=2>been set by method B,&nbsp;MyThread&nbsp;terminates without doing 
anything.&nbsp;On the </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>other hand, if the 
boolean flag has not been </FONT></SPAN><SPAN class=301013917-01042002><FONT 
face=Arial size=2>changed, you basically&nbsp;ARTIFICIALLY generate a button 
A&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>pressed event and 
add it to the system event </FONT></SPAN><SPAN class=301013917-01042002><FONT 
face=Arial size=2>queue of the main application. The system event queue 
</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>will then do the 
scheduling job for you automatically and execute the code in method A. 
</FONT></SPAN><SPAN class=301013917-01042002><FONT face=Arial size=2>Personally, 
I </FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>found coding in this 
way is more&nbsp;</FONT>elegant, since you may not want to mess up with the 
system event</SPAN></DIV>
<DIV><SPAN class=301013917-01042002>queue.</SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial color=#000000 size=2>Hope 
this helps.</FONT></SPAN></DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=301013917-01042002><FONT face=Arial size=2>Lichan 
Hong</FONT></SPAN></DIV>
<BLOCKQUOTE>
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> lian jiang 
  [mailto:jl_vtk@yahoo.com]<BR><B>Sent:</B> Friday, March 29, 2002 9:00 
  PM<BR><B>To:</B> vtkusers<BR><B>Subject:</B> [vtkusers] a problem about 
  multithread and VTK again<BR><BR></FONT></DIV>
  <P>Hi, all:&nbsp;</P>
  <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I&nbsp; posted 
  the&nbsp;mail once&nbsp;but did not receive any response. So I have to post it 
  again&nbsp;and hope someone can&nbsp;give me a help. Sorry to bother you all. 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I met a problem about VTK 
  rendering window and multithread.&nbsp; In my JAVA-VTK program, I have two 
  button, A and B. In the method associated with A, there is an infinite loop, 
  in which the actors are rendered from the first frame to last frame repeatedly 
  in a rendering window. I set a globale variable "boolean jump=false". The 
  infinite loop should exit by judging the value of "jump". In the method 
  associated with button B, I set the variable as 
  true.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; When I click A, the 
  program will enter the infinite loop. I intend to exit the loop whenever I 
  click the button B. But here is a problem. Once the program enters the dead 
  loop, the GUI seems to be stucked and cann't respond to any user action. So 
  the method of B can not set any global variable. 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; From the view of thread, 
  it is easy to understand--because the two buttons are both in the GUI thread, 
  the dead loop will surely block the GUI thread so that button B is 
  disabled.&nbsp;&nbsp;&nbsp; I tried to solve the problem by multithread. 
  Although the loop can exit as I imaged,&nbsp; there still are some 
  problems.&nbsp;If I put the dead loop in a thread, the rendering window can 
  not be refreshed. IF I put the method of B into a thread, button B will also 
  be disable once the program goes into the dead loop.&nbsp;&nbsp;I don't know 
  whether it is a common problem for all kinds of window refreshing.&nbsp; I had 
  studied multithread used in VTK for some time. As far as I know, VTK window 
  will cause some problems in multithread because VTK calls opengl which is not 
  safe for thread. But I am not sure whether the refreshing problem described 
  above is caused by VTK or other reasons.&nbsp; Is it a common problem for all 
  kinds window refreshing?&nbsp; Is there a way to solve this problem?&nbsp; 
  Thank you very much. </P>
  <P><BR>BEST WISHES </P>
  <P>Lian <BR></P>
  <P><BR>
  <HR SIZE=1>
  <B>Do You Yahoo!?</B><BR><A 
  href="$rd_url/welcome/?http://greetings.yahoo.com">Yahoo! Greetings</A> - send 
  greetings for <A 
  href="$rd_url/welcome/?http://greetings.yahoo.com/browse/Holidays/Easter/">Easter</A>, 
  <A 
  href="$rd_url/welcome/?http://greetings.yahoo.com/browse/Holidays/Passover/">Passover</A></BLOCKQUOTE></BODY></HTML>