Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32006
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: javax.swing.Timer blocking program termination |
| Date | 2015-07-14 10:15 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <mo35mi$366$1@dont-email.me> (permalink) |
| References | (1 earlier) <mo1l69$l8g$1@dont-email.me> <mo1m3c$nqg$1@dont-email.me> <mo1p62$m7p$1@dont-email.me> <mo1rc8$ri1$1@dont-email.me> <e1087f9c-0028-44a3-99bf-5c4356626e9d@googlegroups.com> |
On 07/14/2015 09:31 AM, e.d.programmer@gmail.com wrote:
> On Monday, July 13, 2015 at 10:17:14 PM UTC-4, Jeff Higgins wrote:
>> On 07/13/2015 09:35 PM, Jeff Higgins wrote:
>>> On 07/13/2015 08:46 PM, Knute Johnson wrote:
>>>> On 7/13/2015 17:27, Jeff Higgins wrote:
>>>>> On 07/13/2015 07:03 PM, Knute Johnson wrote:
>>>>>> So I have this program that uses a couple of javax.swing.Timers. I
>>>>>> forgot to put in code to stop one of the timers yet the program would
>>>>>> still terminate. I have set the default close operation for the frame
>>>>>> to be DISPOSE_ON_CLOSE.
>>>>>>
>>>>>> What I found was that a timer of less the 1000ms would prevent an
>>>>>> application based on a JFrame from stopping but 1000ms or more and it
>>>>>> would stop just fine.
>>>>>>
>>>>>> I know that javax.swing.Timer uses a common thread for all timers but I
>>>>>> don't see anywhere that describes the stopping behavior.
>>>>>>
>>>>>> The program below will stop if the JFrame is closed and the timer is
>>>>>> 1000ms or greater but hang if it is less. I would be really curious to
>>>>>> know if somebody else can duplicate this.
>>>>>>
>>>>>> import java.awt.*;
>>>>>> import java.awt.event.*;
>>>>>> import javax.swing.*;
>>>>>>
>>>>>> public class test extends JFrame {
>>>>>> public test() {
>>>>>> Timer timer = new Timer(1000,event -> {});
>>>>>> setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
>>>>>> setSize(400,300);
>>>>>> setVisible(true);
>>>>>> timer.start();
>>>>>> }
>>>>>>
>>>>>> public static void main(String... args) {
>>>>>> EventQueue.invokeLater(() -> new test());
>>>>>> }
>>>>>> }
>>>>>>
>>>>>
>>>>>
>>>>> import java.awt.EventQueue;
>>>>> import javax.swing.JFrame;
>>>>> import javax.swing.Timer;
>>>>>
>>>>> public class test extends JFrame {
>>>>> public test() {
>>>>> Timer timer = new Timer(900, event -> {
>>>>> System.out.println("-"); });
>>>>> addWindowListener(new java.awt.event.WindowAdapter() {
>>>>> @Override
>>>>> public void windowClosing(java.awt.event.WindowEvent
>>>>> windowEvent) {
>>>>> System.out.println("Close"); }});
>>>>> setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
>>>>> setSize(400, 300);
>>>>> setVisible(true);
>>>>> timer.start();
>>>>> }
>>>>>
>>>>> public static void main(String... args) {
>>>>> EventQueue.invokeLater(() -> new test());
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>> jeff@debian:~$ javac test.java
>>>>> jeff@debian:~$ java -showversion test
>>>>> java version "1.8.0_40"
>>>>> Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
>>>>> Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
>>>>>
>>>>> -
>>>>> -
>>>>> Close
>>>>> -
>>>>> -
>>>>> -
>>>>> -
>>>>> ^Z
>>>>> [1]+ Stopped java -showversion test
>>>>> jeff@debian:~$ jobs
>>>>> [1]+ Stopped java -showversion test
>>>>> jeff@debian:~$ fg
>>>>> java -showversion test
>>>>> -
>>>>> -
>>>>> -
>>>>> -
>>>>> ^Cjeff@debian:~$
>>>>>
>>>>>
>>>>
>>>> and does it stop on your Linux (I assume) system if the delay is 1000ms
>>>> or more?
>>>>
>>> Very consistantly
>>> With 1000 it continues as long as I can stand.
>>> With 1001 I get
>>> -
>>> Close
>>> -
>>> -
>>> -
>>> -
>>> jeff@debian:~$
>>>
>>> With 1002 I get
>>> -
>>> Close
>>> -
>>> -
>>> -
>>> jeff@debian:~$
>>>
>>> With 1003 I get
>>> -
>>> Close
>>> -
>>> jeff@debian:~$
>>>
>>> With 1500 I get
>>> -
>>> Close
>>> -
>>> jeff@debian:~$
>>>
>>>
>> If I put a timer.stop()
>>
>> addWindowListener(new java.awt.event.WindowAdapter() {
>> @Override
>> public void windowClosing(java.awt.event.WindowEvent windowEvent)
>> { System.out.println("Close"); timer.stop();}});
>>
>> for values of 1000 or less continues to print -
>> for values greater than 1000 doesn't print any - after Close
>
> Why wouldn't a timer stop? I pasted that in and the last thing it always prints is the "Close". I'm running this test in Eclipse Luna on JDK 8 update 45 on Windows 8.1.
>
Re-running, it always closes with timer.stop().
I don't know what I was running with the above?
Now, I still don't know why the short timer1 (below) keeps
the EDT active unless I explicitly stop it in windowClosing?
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.Timer;
public class test extends JFrame {
public test() {
Timer timer1 = new Timer(1000, event -> {});
Timer timer2 = new Timer(1100, event -> {});
Timer.setLogTimers(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
System.out.println("Close");
}});
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(400, 300);
setVisible(true);
timer1.start();
timer2.start();
}
public static void main(String... args) {
EventQueue.invokeLater(() -> new test());
}
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-13 16:03 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 20:27 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-13 17:46 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 21:35 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 22:13 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 22:27 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 06:31 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 10:15 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 10:22 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 07:39 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 10:53 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 10:16 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 13:25 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 10:45 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 14:16 -0400
Re: javax.swing.Timer blocking program termination Gene Wirchenko <genew@telus.net> - 2015-07-14 12:56 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 16:14 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-15 05:11 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 08:33 -0400
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-15 18:46 +0000
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 21:18 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 22:13 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 10:55 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-14 08:17 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 11:42 -0400
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-14 18:35 +0000
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 15:17 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 15:36 -0400
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 15:51 -0400
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-14 21:51 +0000
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-14 15:08 -0700
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-15 01:16 +0000
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 16:09 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 18:32 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 18:34 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 20:31 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-14 08:16 -0700
Re: javax.swing.Timer blocking program termination Joerg Meier <joergmmeier@arcor.de> - 2015-07-14 08:32 +0200
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 22:18 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 08:26 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-15 11:05 -0700
csiph-web