Killing an Updater Thread when I stop watch an JPanel

Hi,
Firstly this is proably really bad code convention. What I am wondering is how to fix my problem and perhaps some guidance on what to do instead, I am unsurre as to how to model an Updater thread on a JPanel. What I am doing is updating the Icons in JTree when the data changes, this happens continally so there is no start finish defined.
I thought I could use isVisible() to work out when to terminate my updater thread, ut that doesnt seem to be the case. Any Ideas on what to do???
Thanks a Mill,
Anthony
public class MyTreePane extends TreePane {
     private boolean start = true;
     public XRiskHistoTreePane() throws Exception {
          super();
      * This threads jobs is to scan the
     private void startScannerThread() {
          Runnable  r = new Runnable(){
               public void run(){
                    int [] keys = getRiskKeys();
                    while(isVisible()){
                         for(int i = 0; i < keys.length; i++){
                              try {
                                   Reporter rep = UpdateClient.getPosition(keys);
                                   PercentageIcon icon = null;     
                                   if(rep != null){
                                        int per = (int) rep.getPercentage();
                                        icon = new PercentageIcon(per);
                                   setImageIcon(keys[i], icon);
                              } catch (Exception e) {
                                   e.printStackTrace();
          Thread t = new Thread(r);
          t.setName("Update Thread");
          t.start();
          t.setPriority(Thread.MIN_PRIORITY);
     public void paint(Graphics visible){
          super.paint(visible);
          if(start){
               startScannerThread();
               start = false;

Hi,<br> Firstly this is proably really bad code convention. What I am wondering is how to fix my problem and perhaps some guidance on what to do instead, I am unsurre as to how to model an Updater thread on a JPanel. What I am doing is updating the Icons in JTree when the data changes, this happens continally so there is no start finish defined. I thought I could use isVisible() to work out when to terminate my updater thread, ut that doesnt seem to be the case. Any Ideas on what to do???
<br>
Thanks a Mill, Anthony
<pre>
public class XTreePane extends TreePane (which extends JPanel) {
     private boolean start = true;
     public XTreePane() throws Exception {
          super();
     * This threads jobs is to scan the
     private void startScannerThread() {
          Runnable r = new Runnable(){
               public void run(){
                    int [] keys = getKeys();
                    while(isVisible()){
                         for(int i = 0; i < keys.length; i++){
                              try {
                                   Reporter rep = UpdateClient.aggregationPosition(keys);
                                   PercentageIcon icon = null;     
                                   if(rep != null){
                                        int per = (int) rep.getPercentage();
                                        icon = new PercentageIcon(per);
                                   setImageIcon(keys[i], icon);
                              } catch (Exception e) {
                                   e.printStackTrace();
          Thread t = new Thread(r);
          t.setName("Update Thread");
          t.start();
     public void paint(Graphics visible){
          super.paint(visible);
          if(start){
               startScannerThread();
               start = false;
</pre>

Similar Messages

  • Stop Watch Malfunction?

    My son plays baseball so I use the stop watch function to time his base running (during practice only). Tonight when the stop watch got to about 15 seconds, it added about 45 - 47 seconds to the time. It adds the time and keeps on counting. I have never noticed this before and I have used this function regularly. I have had this phone since the last week of July. Now, granted it is not a MAJOR issue, but still and issue. Any others notice this?

    Have you upgraded to 1.1.1. I've heard of this problem but can't reproduce it under 1.1.1.

  • How can i say yes to automatic updates when they stop my wireless dlink to Virgin home broadband from getting on the internet and then i have to do a system restore to the day before the update to get it back to normal?!? Frustrated

    how can i say yes to automatic updates when they stop my wireless dlink to Virgin home broadband from getting on the internet and then i have to do a system restore to the day before the update to get it back to normal?!? Frustrated
    == This happened ==
    Not sure how often
    == automatic updates go on my computer, say if i click yes to update when shutting down

    You have 10.6 on that machine, I suggest you stick with it for performance, third party hardware and software reasons as long as possible.
    Consider 10.8 (not 10.7) when it's released, because 10.7 and 10.8 will require a new investment in software and newer third party hardware as it requires newer drivers the old machines won't have. (forced upgrade because of software, really nice of them)
    http://roaringapps.com/apps:table
    Far as your Safari problem do these things until it's resolved:
    1: Software Update fully under the Apple menu.
    2: Check the status of your plug-ins and update (works for all browsers) also install Firefox and see if your problems continue. You should always have at least two browsers on the machine just in case one fails.
    https://www.mozilla.org/en-US/plugincheck/
    Flash install instructions/problem resolution here if you need it.
    How to install Flash, fix problems
    3: Install Safari again from Apple's web site
    https://www.apple.com/safari/
    4: Run through this list of fixes, stopping with #16 and report back before doing #17
    Step by Step to fix your Mac

  • Hey, i have a ps3 slim and when i try to update always my ps3 stop in 99% help please

    hey, i have a ps3 slim and when i try to update always my ps3 stop in 99% help please

    Please post your concern on Sony PlayStation Community here for further assistance. Thank you! 
    If my post answers your question, please mark it as "Accept as Solution"

  • Stopping a Thread when downloading

    Hi everyone!
    I'm develop a app to connect to a FTP Server and dowload and upload files. When I click on Cancel button, the app will still running but the download will stop.
    So, my problem is: How can I stop a Thread when i'm donwloading a file?
    I'm using Commons Net 3.0.1 to connect from a FTP. I have tried logout(), disconnect(), abort()... Into Threads I have tried interrupt(), yield(), stop(), destroy()... But not works!
    The "safe way to stop a Thread" don't work for me, becouse I'm not using a While but yes this line code to download the file:
    ftp.retrieveFile(TARGET, SOURCE);
    When I click on cancel button the donwload still running in background.
    PS: Sorry for my english :)

    Problem solved! Using the method retrieveFileStream() and the famous "the safe way to stop a Thread" I can stop it without need to close my app!
    The code was (adapted):
    OutputStream os;
    InputStream is;
    localDownload = new FileOutputStream(new File(LOCAL, NOME_ARQUIVO));
    os = localDownload;
    is = ftp.retrieveFileStream(LOCAL_FTP+NOME_ARQUIVO_FTP);
    if(is != null){
         int bytesRead = -1;
         final byte[] buffer = new byte[4096];
         while ((bytesRead = is.read(buffer)) != -1){
              if(cancelado == false)
                   os.write(buffer, 0, bytesRead);
              else
                   cancelado = false;
    is.close();
    ftp.completePendingCommand();PS: The method completePendingCommand() is fundamental for the download can be stoped.
    Again: sorry for my english :)
    Edited by: 866587 on 17/06/2011 09:53

  • When i try to update cc downloadcenter it, stops after a while and shows an error

    when i try to update cc downloadcenter it, stops after a while and shows an error ?

    i tried every solution you suggested but nothing helped. And when i tried to download the cc desktop app.again it stopped downloading and gave an error code 207 and message that it could not
    contact the server. ( i had internet open all the time and every other site wasconnected ) My premiere pro cc does also quit working when i try to do something ?

  • Hi everyone, I'v got some tech problem when I am watch youku video. It often got stuck and just stop broadcasting the video. I am wondering if it was sort of bugs of 10.7.4 versions?

    hi everyone, I'v got some tech problem when I am watch youku video. It often got stuck and just stop broadcasting the video. I am wondering if it was sort of bugs of 10.7.4 versions?

    Do you have a link to this youku video?

  • HT4972 I am using iphone 4 Geveya in which I have to dial 112 after re-insertion of Sim Card. When i connect my phn to I tunes I got message to update the version of iphone. Some one has informed me that I can not update this phn will stop workin after up

    I am using iphone 4 Geveya in which I have to dial 112 after re-insertion of Sim Card. When i connect my phn to I tunes I got message to update the version of iphone. Some one has informed me that I can not update this phn will stop workin after update.
    Kindly update me on this whether I need to update this or not.

    Try a Hard Reset.....
    Press and hold the Wake / Sleep button AND the Home button at the same time, keep them both pressed until the Apple Logo appears on the screen, it can take 10 or more seconds.  Ignore the swipe to turn off message.

  • My hp support assistance wont run. it keeps stopping during updates and when deleting the temporary

    My hp support assistance wont run. It keeps stopping during updates and when deleting the temporary internet files. So it never finishes the process.. help

    The failure to remove the Temporary Files could just be due to having your internet connection active during the removal process.  For most folks, the amount of data in this directory is minimal.   If you want / need to remove the files, you could close your browser(s), make sure your Internet music and TV connections are closed, and then try removing the files manually:
    Path to Folder:
    C:\Users\--YourAccountNameHere--\AppData\Local\Microsoft\Windows\Temporary Internet Files
    Warning: 
    Do NOT remove the "Temporary Internet Folder" itself.  Go "inside" the folder before removing anything.
    ==================================================​==================================
    The HP Support Assistant is great when it works -- and not so great when it won't cooperate.  You can try removing the program from your computer and installing it again.  That may work.
    Control Panel > icon view > Programs and Features >
    Scroll down, find, and Uninstall HP Support Assistant.
    Restart your computer after uninstalling the existing version of Support Assistant.
    Install Support Assistant
    HP Support Assistant
    Using HP Support Assistant (Windows 8)
    Troubleshooting HP Support Assistant
    NOTE:  At writing, there are possible issues with HPSA version 7.x -- you might want to sitck with version 6.x for now.
    ==================================================​====================================
    If you have issues removing your version of HPSA:
    Fix problems with programs that can't be installed or uninstalled
    ==================================================​===================================
    Workaround to get Updates:
    If all avenues fail to bring joy and it just won't work, you can still get your updates from your computer's website.
                                                      ​         Install Software and Drivers from HP Website
    Go to the top of the HP forum page to Support and Drivers
    If prompted, Enter your Country or Region and
    Enter your Computer Model information,
    Go to Software and Drivers...
    Enter your Operating System in the Drop-down menu...  Scroll down
    Select desired Category
    Expand and decide if you need to install that package.
    Assure that you download and install only the most recent versions of each driver or program.
    Save the appropriate *.exe installation package on your computer
    NOTE the name and the location - the *.exe file will likely save to "Downloads “
    Install the Software / Driver installation package:  If you have ‘Admin’ control, you may highlight the package(s) and “double-click” to install, else Right-Click, Select ‘run as Administrator’ and install.
    NOTE:  There is sometimes a lot of information at the computer’s website.  Be sure to take an extended look at what’s available.
    ==================================================​====================================
    Good Luck!
    Kind Regards,
    Dragon-Fur

  • Plugin Container for Firefox has stopped working. Also Real Player says it needs update but when I try it says newest version is already insatlled.

    Constant crashes , Plugin Container for Firefox has stopped working. Also Real Player says it needs update but when I try it says newest version is already installed.

    Google Earth Plugin
    GEPlugin Outdated Version Update
    Plugin Icon
    RealPlayer Version Plugin
    6.0.12.69 Outdated Version
    Still saying I need updates but when I update it says I have current versions already.
    Also still keep getting plugin container for firefox has stopped working. But I'm not see a problem with anything.

  • You tell me to uppdate Firefox on my MAC Air, it is impossible, I get to 1,5 mb than it stops, MAC support tell me that it is not posible to update Firefox when I am on Firefox, tell me hove to update, bgjestla@online.no

    Question
    Hello from Norway with a bad Englisch.
    You tell me to uppdate Firefox 3.6 on my MAC Air, it is impossible, I get to 1,5 mb than it stops, MAC support tell me that it is not posible to update Firefox when I am on Firefox, tell me hove to update, [email protected]

    about:crashes only lists crashes that you have reported using the [[Mozilla Crash Reporter]] which comes up after a crash. Because there are so many possible reasons for a crash, getting the crash ID really helps volunteers find the cause quicker.
    That doesn't mean we can't help without a crash id. :-) No crashes here, but I'm also on Snow Leopard and using Firefox 3.6.6.
    Are you using Firefox 3.6.6? The most common cause of crashes on Mac is the Flash plugin. Are you using the latest version of Flash? You can check at http://www.mozilla.com/en-US/plugincheck/
    Do you remember any specific circumstances about when the crash occurred? What sites you were on?

  • Problems with a simple stop watch program

    I would appreciate help sorting out a problem with a simple stop watch program. The problem is that it throws up inappropriate values. For example, the first time I ran it today it showed the best time at 19 seconds before the actual time had reached 2 seconds. I restarted the program and it ran correctly until about the thirtieth time I started it again when it was going okay until the display suddenly changed to something like '-50:31:30:50-'. I don't have screenshot because I had twenty thirteen year olds suddenly yelling at me that it was wrong. I clicked 'Stop' and then 'Start' again and it ran correctly.
    I have posted the whole code (minus the GUI section) because I want you to see that the program is very, very simple. I can't see where it could go wrong. I would appreciate any hints.
    public class StopWatch extends javax.swing.JFrame implements Runnable {
        int startTime, stopTime, totalTime, bestTime;
        private volatile Thread myThread = null;
        /** Creates new form StopWatch */
        public StopWatch() {
         startTime = 0;
         stopTime = 0;
         totalTime = 0;
         bestTime = 0;
         initComponents();
        public void run() {
         Thread thisThread = Thread.currentThread();
         while(myThread == thisThread) {
             try {
              Thread.sleep(100);
              getEnd();
             } catch (InterruptedException e) {}
        public void start() {
         if(myThread == null) {
             myThread = new Thread(this);
             myThread.start();
        public void getStart() {
         Calendar now = Calendar.getInstance();
         startTime = (now.get(Calendar.MINUTE) * 60) + now.get(Calendar.SECOND);
        public void getEnd() {
         Calendar now1 = Calendar.getInstance();
         stopTime = (now1.get(Calendar.MINUTE) * 60) + now1.get(Calendar.SECOND);
         totalTime = stopTime - startTime;
         setLabel();
         if(bestTime < totalTime) bestTime = totalTime;
        public void setLabel() {
         if((totalTime % 60) < 10) {
             jLabel1.setText(""+totalTime/60+ ":0"+(totalTime % 60));
         } else {
             jLabel1.setText(""+totalTime/60 + ":"+(totalTime % 60));
         if((bestTime % 60) < 10) {
             jLabel3.setText(""+bestTime/60+ ":0"+(bestTime % 60));
         } else {
             jLabel3.setText(""+bestTime/60 + ":"+(bestTime % 60));
        private void ButtonClicked(java.awt.event.ActionEvent evt) {                              
         JButton temp = (JButton) evt.getSource();
         if(temp.equals(jButton1)) {
             start();
             getStart();
         if(temp.equals(jButton2)) {
             getEnd();
             myThread = null;
         * @param args the command line arguments
        public static void main(String args[]) {
         java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
              new StopWatch().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JPanel jPanel1;
        // End of variables declaration                  
    }

    Although I appreciate this information, it still doesn't actually solve the problem. I can't see an error in the logic (or the code). The fact that the formatting works most of the time suggests that the problem does not lie there. As well, I use the same basic code for other time related displays e.g. countdown timers where the user sets a maximum time and the computer stops when zero is reached. I haven't had an error is these programs.
    For me, it is such a simple program and the room for errors seem small. I am guessing that I have misunderstood something about dates, but I obviously don't know.
    Again, thank you for taking the time to look at the problem and post a reply.

  • Add Stop Watch in Form using LiveCycle Designer

    Hi,
    How can I add a stop watch into a Form created with Adobe Live Cycle Designer 8.0?
    Basically I'd like the following:
    I am creating a read-out form for a radiologic study. So the reader should be able to push a button on the very beginning of the form which should trigger a stopwatch to start. At the very end of the form, there should be a 2nd button which the reader can push when he's finished reading and filling out the form to stop the stop watch which was running in the background. The resulting time should then be displayed and saved in a field for export to Excel later on. Is this possible using JavaScript?
    If this doesn't work, alternatively there could be a button to push in the beginning of the form which would put the actual Date/Time in a Field and at the bottom of the Form a second button which would again show the actual date/time in a field. This way I would export the two fields into Excel and then let Excel calculate the needed time to fill out the form.
    When I add a Date/Time Field, it updates, whenever someone makes a change to the form.
    Thank you for your help,
    Olivio Donati

    There is no stop watch per se.... but your technique of getting the time should work here. On the click event of the Start button you will need to record the time in a hidden field (so you can get at it later). On the Finish button you can record the time again and then get the difference between the stop and start time. FormCalc has some built in functions that will change a given time to the number of milliseconds that have elapsed from a specific epoch. You will need this to do the time calc.

  • Killing a Swing thread

    Hello,
    How can I kill a Swing thread? For example the program below would never exit. Sure you can type System.exit(0) which would exit anything, but what are the other solutions?
    I tried putting chooser = null;
    System.gc();in the end of main() but this won&#8217;t work.
    To formulate my question better - how would I kill a thread I do not have complete command of (i.e. I can&#8217;t do usual do/while thread stopping)?
    Big thanks in advance.
    public class SwingLiveTest{
        public static void main(String[] args) {
            JFileChooser chooser = new JFileChooser();
            if (chooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) return;
            File file = chooser.getSelectedFile();
            System.out.println(file);
            /*chooser = null;
            System.gc(); */

    You can't kill any Thread like this, at least not those where there is no method to call.
    It is possible to cause a Thread to stop, call the stop method, however this is not the recommended approach for very good reasons (Read the JavaDocs for java.lang.Thread.stop() method to see why.
    It should be possible, once you have obtained a reference to the Thread you wish to stop, to call interrupt() on that Thread.
    This is not guaranteed to work because you are dependent on the implementation of the Thread class you are manipulating or the Runnable that the Thread instance is currently running.
    There may be classes in the com.sun packages which can aid you with this problem, this is where Sun usually sticks undocumented implementation however these packages are not officially supported and there is no guarantee that classes you use in one VM are available in another, in particular when the VM you are using is not a Sun VM.

  • Satellite L755 PSK2YE - Dvd writer blinks when I am watching movies

    Hi
    I have a Toshiba Satellite L755 PSK2YE with windows 7 64 bit
    The Dvd writer blinks when I am watching movies
    Do i need to update the BIOS or what >> BIOS 2.70 to 2.78

    I've the same problem but not only when watching the movies, but randomly for at least couple of times each 30 minutes !!
    I've Satellite L750-A057
    BTW, check this :
    http://forums.computers.toshiba-europe.com/forums/thread.jspa?messageID=265064&#265064
    I'll try the solutions mentioned their and feed you back.
    Message was edited by: Mahmoud Abdel-Fattah

Maybe you are looking for

  • I have a basic applet method timing problem with Firefox (and Chrome), not IE nor Opera. Works if JavaScript issues windows.alert() prior, fails otherwise.

    I have an applet method, which is invoked from a JavaScript function, that is triggered by the window.onload event. The problem seems to center in the loading of the applet and its methods. If I step through the 3 applet acceptance prompts (I chose t

  • Identifying/resizing animated GIF

    Hi This is my situation: I load user-selected image files (any format is OK, the more the better) for later transmission as byte array, always re-encoded as JPG. If the image is over some certain width/height, I scale down the image (display size iss

  • Order by is not working

    Hello, I'm using FORM 6i and writing the data to Excel Report I'm passing the string to the Order By clause. But the data is not sorted. Code is as follows: procedure test (pi_order IN VARCHAR2) is type t_data IS REF CURSOR; c_data t_data; l_order_by

  • Skype on Mac - /alertsoff (still) does not work in...

    Hi there, unfortunately you've closed this thread (http://community.skype.com/t5/Mac-archive/alertsof​f-doesn-t-work-Skype-team-please-fix-the-bug/m-p/7​... without fixing the bug. I'm on OSX Yosemite (10.10.3) and when typing /alertsoff in a group c

  • 311 movement  no valuation

    Hi, We want to transfer a material from one storage location to another using the movement 311 and we have realized that with that movement type there is no valuation, so with transaction MB51 the material stock is correct in both storage locations (