Should I use two threads which can kill each other?

I would like to have a window with a simple form (radio buttons and so on). Users can make there selections and press a "Submit" button. Additionally to that I would like to set some time limits. In more details, user should see how many seconds he/she still have (so, there should be a timer). If the time limit is exceeded, program close the window and submit a "default" selection.

As far as I understand I need to generate 2 threads for that. One will monitor the user activity in the window (which radio button is selected and so on).

Another thread should create a timer which check the remaining time every second and put this information, in some way, into the window.

Moreover, these two thread should be able to kill each other. For example, if the "Submit" button is pressed, the first thread kills the timer. Or if the time is exceeded the second thread (timer) kill the first process.

Is it a good architecture? I need your opinion since I do such kind of things for the first time.

Answers


While being somewhat awkward, it is possible for two threads to kill each other.

However, I don't think you need two threads.

You can use a Swing timer (see this tutorial) to run the clock. When you click "Submit" you can stop the timer by invoking its stop() method. The beauty is that Swing timers run on the GUI thread so you don't get the concurrency headache.


Need Your Help

Git error on commit after merge - fatal: cannot do a partial commit during a merge

git commit

I ran a git pull that ended in a conflict. I resolved the conflict and everything is fine now (I used mergetool also).