Results 1 to 3 of 3
  1. #1
    shall is offline Senior Member
    Join Date
    Apr 2012
    Rep Power

    Default Interrupting a thread


    I created a serial event handler that uses threadToInterrupt.interrupt to interrupt a protocol state machine, which is running in it's own thread. threadToInterrupt is a thread object that is passed to the serial event handler method's class.

    The user may decide to close the program at the same time the serial event happens. What is the best way to handle multiple interrupts that happen at the same time?

    Last edited by shall; 09-11-2015 at 05:07 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Interrupting a thread

    There are probably better ways to do this (I don't do much thread programming) but assuming your interface handler is properly synchronized, you could set a variable indicating that the interrupt has already been processed. And while processing that interrupt you would want to disable future interrupts from occurring. Not certain how you are using threads but Java has a rich set of classes to facilitate thread programming.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    shall is offline Senior Member
    Join Date
    Apr 2012
    Rep Power

    Default Re: Interrupting a thread

    Hello Jim,

    Thanks for the reply.

    I had previously added the flag whose state is returned by serialComm.serialEventInterruptOccurred() (see code below). What I am perplexed about is how to handle a close application event that occurs immediately after I start processing the the serial event interrupt. I would like to exit the protocol state machine thread when the close application event occurs.

    However, maybe I don't have to worry about it at all.

    Java Code:
                try {
                } catch (InterruptedException ex) {
                    if (serialComm.serialEventInterruptOccurred()) {

Similar Threads

  1. Replies: 2
    Last Post: 12-11-2012, 11:35 AM
  2. Mouse click interrupting animation
    By rolledback in forum Java 2D
    Replies: 17
    Last Post: 06-16-2011, 11:01 PM
  3. Replies: 0
    Last Post: 04-26-2011, 03:43 PM
  4. interrupting urlconnection's outputstream
    By zynasis in forum Networking
    Replies: 5
    Last Post: 10-02-2008, 12:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts