Very weird bug

Discussion in 'Plugin Development' started by mcat95, Feb 28, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    mcat95

    Ok, this is a very weird bug. First the code:
    Code:
    javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                if (ongame == true) {
                    //some non-related code 
                    temp -=1;
                    if (temp== 0) {
                        plugin.getServer().shutdown();
                    }
                }
            }
    });
    Sometimes the servers closes before the time gets to 0. I don't understand why, but it's totally random and i am a bit confused about this
     
  2. Offline

    Cjreek

    Maybe you could try a repeating task instead of a timer?
     
  3. Offline

    mcat95

    Cjreek I prefer the timer because it's easier to stop/start/restart/etc
     
  4. Offline

    gomeow

    Schedulers was designed for these purposes, use what is provided

    https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks
     
  5. Offline

    wacossusca34

    Additionally, the Timer object executes its code through a background thread.

    From the javadocs:
    A lot of issues can occur when executing from anything but the main thread. Like gomeow said, use what is provided.
     
  6. Offline

    mcat95

Thread Status:
Not open for further replies.

Share This Page