Can one actionListener interrupt another?

Good afternoon,
I've searched these forums and online for a solution to my problem, but I have had no luck thus far. In my JSF application, I have a page with multiple buttons bound to actionListener methods in the backing bean. One such button ('Start') initiates a process that could run indefinitely (to a maximum number of iterations as configured by the user), and another button ('Stop') is intended to terminate the first process at some user-specified time, if they want to stop it before it reaches it maximum.
(Both buttons/methods operate over private member data in a session scope bean -- there's no need to worry about coordinating communication between objects, just about two methods in the same object.)
I manage the interaction between the two methods via a separate class (each instance of the backing bean class gets its own instance of this manager class) with synchronized access to the flags that define the current state of Start's process. When the user clicks 'Stop', the bound method updates a flag that indicates the process should stop immediately (at the end of the 'Start' method's current loop iteration) and then calls a method that forces it to wait() until 'Start' finishes its processing and calls notifyAll(). Debugging through the interaction of the two threads, it looks like the mutli-threading control code works correctly.
When we actually get into the 'Stop' method's code, that is. What I am seeing is that after I click 'Start', while the request is still in the Invoke Application phase of the life cycle, if I then click 'Stop', the page is immediately rendered without completing the current iteration of the 'Start' method (and without the final processing step that method performs). In my debugger, I see that this first click of 'Stop' doesn't even hit the backing bean at all. It takes a second click to invoke the method bound to the button, at which point the multi-threading code executes as expected.
I could work around this problem by performing my "post-loop processing" as the final step inside the loop, but this could result in potentially expensive data massaging being needlessly performed many times. I could also treat it as a user-education issue and just tell them to click the button twice, but that's hardly professional. :-) I'm wondering if there's some well-known limitation that I'm not aware of, or (hopefully) some well-known solution to the problem of one actionListener seeming to abort while another is in process.
Thanks in advance for any help or advice,
Roger Alix-Gaudreau

Yes, that's pretty much what's happening. I thought that with both components being bound to the backing bean via actionListener elements (instead of action elements), I would be able to use some multithreading code to force the second click's processing to wait until the first was complete, thus making them end at the same time. I guess the technology doesn't quite support that approach, however. I should probably do some reading to get a deeper understanding of the technology...
Given that your guess that we're trying to interrupt one request with another is correct, I'm not sure if posting the code will help (except to confirm that guess), but here is the code for the buttons from the JSP page:
<h:commandButton styleClass="kiosk_cmd" id="btnStart"
   onclick="document.body.style.cursor = 'wait';"
   rendered="#{userSessionBean.viewableCompsMap['ReadEPCs.StartRead']}"
   disabled="#{userSessionBean.disabledCompsMap['ReadEPCs.StartRead']}"
   value="#{msgBundle.EPCMGR_Common_StartReadButton}"
   actionListener="#{readBean.doRead}"
   title="#{msgBundle.EPCMGR_Common_StartReadButtonTooltip}"/>
<h:commandButton styleClass="kiosk_cmd" id="btnStop"
   onclick="document.body.style.cursor = 'default';"
   rendered="#{userSessionBean.viewableCompsMap['ReadEPCs.StopRead']}"
   disabled="#{userSessionBean.disabledCompsMap['ReadEPCs.StopRead']}"
   value="#{msgBundle.EPCMGR_Common_StopReadButton}"
   actionListener="#{readBean.doStopRead}"
   title="#{msgBundle.EPCMGR_Common_StopReadButtonTooltip}"/>The method backing the Start Read button looks like this:
public void doRead(ActionEvent ae){
   //notify the StopReadManager that we're now reading
   stopMgr.setReading(true);
   loadReaderParms(EPCMgrConst.APP_LAYER_TRAN_READ,EPCMgrConst.APP_LAYER_ACT_READTAGS);
   if(!isReaderActive()){
      m_Logger.displayMsg(EPCMgrUtil.getMessage(EPCMgrConst.EPCMGR_ErrorKey_ReaderNotActive),EPCMgrConst.MSG_TYPE_ERROR);
      stopMgr.setReading(false);
   //build map of keyfields for request XML
   Map keymap= new HashMap();
   keymap.put(EPCMgrConst.XML_KEYVAL_DURATION, getDuration());
   keymap.put(EPCMgrConst.XML_KEYVAL_INTERVAL, getInterval());
   keymap.put(EPCMgrConst.XML_KEYVAL_CNTRINFO, "1");
   //perform the read(s), get epc data
   int readCycle= 0;
   while(readCycle < getMaxReads() && !stopMgr.isStopNow()){
      doStartRead(keymap);
      readCycle++;
      buildTagDisplayData();
   //notify the StopReadManager that we're done reading
   stopMgr.setReading(false);
}The code backing the Stop Read button looks like this:
public void doStopRead(ActionEvent ae){
   if(stopMgr.isReading()){
      stopMgr.setStopNow(true);
      while(!stopMgr.isReadingFinished()){
         //do nothing, the call waits until reading is done.
      //reset the StopReadManager
      stopMgr.setStopNow(false);
}And lastly, the code for the StopReadManager that those methods refer to:
public class StopReadManager {
   private boolean reading;
   private boolean stopNow;
   public StopReadManager(){
      reading= false;
      stopNow= false;
    * Producer for the reading flag is the "StartRead" process, consumer is "StopRead".
    * StartRead must set it to true when reading is in progress, StopRead should
    * only be able to exit a call to this method when reading is done (i.e. when
    * StartRead sets the reading flag to false.)
    * @return True when reading is finished.
   public synchronized boolean isReadingFinished(){
      while(reading){
         try{
            wait(); //Wait until StartRead is complete
         }catch(InterruptedException ie){ }
      //We are done reading.
      return true;
   public synchronized boolean isReading(){
      return reading;
   public synchronized void setReading(boolean value){
      reading= value;
      //If no longer reading, notify any threads waiting on the lock.
      if(!reading)
         notifyAll();
   public synchronized boolean isStopNow(){
      return stopNow;
   public synchronized void setStopNow(boolean value){
      stopNow= value;
}As I mentioned, the multithreading control code works correctly, once we hit it, which happens the second time I click the Stop button. The first time I click it, the screen immediately reloads (though the Start process continues in the background). So what I really need is the ability to make sure that if I click Stop while Start is still processing, it actually hits the backing bean code and enters the multithreading control code properly. You metion something called "shale's token". What is that, and how can it solve my problem?
Thanks,
Roger Alix-Gaudreau

Similar Messages

  • One Socket Interrupting another Socket

    In my application I am attempting to talk to another application on the same computer via Socket port connections. The other software works as both a server and a client, meaning that it will attempt to connect to my application as a client, and expects my application to connect to it as a client.
    I set my application to receive connections on port 6001 using a ServerSocket object. Once my application accepts the connection from the other application I send the InputStream of the resulting Socket object to be read and handled. This is working fine for me.
    Next when my application attempts to connect to the other application using a Socket object (separate from the one created by the ServerSocket.accept() method and in a different thread) and it should connect via port 6002. The InputStream that I sent to be handled starts giving me the end of stream, and I can't process data coming from the other application any more.
    Does anyone know what I may be doing wrong in this case?

    JRSofty wrote:
    In my application I am attempting to talk to another application on the same computer via Socket port connections. The other software works as both a server and a client, meaning that it will attempt to connect to my application as a client, and expects my application to connect to it as a client.
    I set my application to receive connections on port 6001 using a ServerSocket object. Once my application accepts the connection from the other application I send the InputStream of the resulting Socket object to be read and handled. This is working fine for me.
    Next when my application attempts to connect to the other application using a Socket object (separate from the one created by the ServerSocket.accept() method and in a different thread) and it should connect via port 6002. The InputStream that I sent to be handled starts giving me the end of stream, and I can't process data coming from the other application any more.
    Does anyone know what I may be doing wrong in this case?The way you use the verbs "send" and "sent" seems very odd.
    It is clear enough that only the client (the one that did the connect) is allowed to write to the socket.
    You are using the sockets in half duplex mode.
    Does anyone know what I may be doing wrong in this case?You are saying your peer application connects to your application, then
    your application connects to your peer application and very quickly you get EOS on this outgoing socket?
    Is there some kind of application level ACK built in to this system?
    Is there anything preventing you from just opening another connection to your peer application?
    Not sure how you can know how much data reached your peer application before you got EOS.
    Maybe your peer application does not read from the socket at all? In that case you will get an exception once your local TCP send buffer is full.

  • Can One iPhone Recognize Another Just By The Phone Number?

    Hello and Merry Christmas. I have an unusual question. I typed in a friend's cell phone number in the text message box on my iPhone and instead of getting an ordinary message in green, it said "iMessage" and when I sent the message, the text was in blue. I have not been in contact with this friend for awhile so I have no idea if he has an iPhone or not.
    Is it possible for one iPhone to recognize another one just my the telephone number? I am worried that he won't get my text unless he too has an iPhone. I message all the time and I have never seen this "iMessage show up before in the texting window??? If anyone can help me with an answer to this question, please do. There is nothing that I did differently, the phone did this by itself. Thanks in advance, Mike

    Yes, your iPhone can recognize another iOS device using iOS 5 (and therefore iMessage). As long as the other iOS device owner has iOS 5 and they have the iMessage feature enabled then whenever you text them it will revert to the blue bubbles to indicate that it is using iMessage instead of your text message plan.
    The only time it will revert to iMessage is if the person at the phone number you are texting actually has an iPhone with iOS 5. If they switch to a different device it will no longer  switch to the iMessage service. You don't have to worry about that. There are times that the iMessage service may be down or not working...in those cases your messages will send as regular text messages (unless you have that feature turned off in settings).

  • Interrupt from one thread to another

    I have a two threads. When one thread fails in its process, I want to stop another thread also. The problem is, the process of thread is not in my control.
    public class TestJoin {
            public static void main(String a[]) {
              MyThread t1 = new MyThread(5,"one");
              MyThread t2 = new MyThread(5000,"two");
              t1.setTH(t2);
              t2.setTH(t1);
              t1.start();
              t2.start();
              try {
                t1.join();
                t2.join();
            catch (InterruptedException e) {
                System.out.println("InterruptedException###");
                e.printStackTrace();
          class MyThread extends Thread{
            int counter;
            String status,threadName;
            Thread another;
            public void setTH(Thread another) {
                this.another = another;
            MyThread(int i, String threadName) {
              this.counter = i;
              this.threadName = threadName;
            public void run() {
               try {
                   int i=0;
                   for(i=0;i<this.counter;i++) {
                      // System.out.println(threadName+"->counter:"+i);
                   System.out.println(threadName+"->counter:"+i);
                   System.out.println("I am interruppting thread:" +another.getName());
                   another.interrupt();
            catch (Exception e) {
                e.printStackTrace();
    }Here I used for loop to demonstrate, actually I use commons http client's (HttpClient).executeMethod(filePost). It gives me control only after finishing process or when exception occurs.
    My need is if exception occurs, I dont want the another thread to upload.
    Any idea will be appreciated.

    How about this?
    class MyThread extends Thread{
            int counter;
            public String status,threadName;
            MyThread another;
            public AtomicBoolean interrupted = new AtomicBoolean(false);
            public void setTH(MyThread another) {
                this.another = another;
            MyThread(int i, String threadName) {
              this.counter = i;
              this.threadName = threadName;
            public void run() {
               try {
                   int i=0;
                   for(i=0;i<this.counter;i++) {
                      // System.out.println(threadName+"->counter:"+i);
                        if (i % 1000 == 0 && interrupted.get()) {
                             System.out.format("Thread %s detected interrupt at iteration %d.\n", threadName, i);
                             break;
                   if (!interrupted.get()) {
                        System.out.println(threadName+"->counter:"+i);
                        System.out.println("I am interruppting Thread " + another.threadName);
                        another.interrupted.set(true);
            catch (Exception e) {
                e.printStackTrace();
    }Uses an AtomicBoolean that can be set by another thread and is checked every nth iteration (where n is 1000 in this example).

  • How can i transfer my music from one account to another on a different computer?

    So i have an itunes account on dell laptop and i share that account with other famliy members. I recently bought a mac pro and wanted to create a new account that way i can use icloud, is there any possible way to transfer everything from my old library to my new one or will i lose everything i had on my phone and ipods? Or is it possible to have one account but multiple icloud accounts?

    lisafromwindermere wrote:
    I want to start my own account separate from my parents. Can I transfer my music from one account to another? If so, how?
    Lisa,
    Just get copies of the song files and add them to your iTunes library.  With the exception of any DRM-protected files (purchased before mid-2009 and never upgraded) they will play fine, even though they are technically associated with the original account.

  • How can i move music from one account to another

    I have 4 different accounts in Itunes and i wish to move all the music into one account
    help please !!!!

    You can't transfer content from one account to another account, nor can you merge accounts - content will remain tied to the account that downloaded it

  • How can I transfer sapscript from one client to another

    Please tell me the steps , how can I <b>transfer</b> SAPscript from one client to another (like DEV Client to Test Client)?

    Hi,
    Utilities --> Copy from client.
    If you have to copy from once system to another use Program RSTXSCRP
    Regards,
    Satish
    Message was edited by:
            Satish Panakala

  • How can I transfer mailboxes from one computer to another?

    How can transfer all mailboxes(and their contents from one MBP to another? Migration assistant was no help.

    Select all your mailboxes, and then select
    Mailbox ▹ Export Mailbox...
    from the Mail menu bar. Export the mailboxes to the Desktop folder. Transfer them to the new machine.
    On the new machine, import the mailboxes:
    File ▹ Import Mailbox...

  • How can i transfer songs from one itunes to another?

    I have a new computer and want to transfer all of my songs from one computer to another.  I have home sharing turned on but can't figure out how to save the songs to the new computer.

    I have home sharing turned on but can't figure out how to save the songs to the new computer.
    First, make sure you've got the home share set up on both computers, as per the following document. If material on the original PC was bought from the iTunes Store, I'd use the AppleID you used for the purchases to set up the Home Share on both PCs.
    iTunes: Setting up Home Sharing on your computer
    Have both computers running and have iTunes open on both computers.
    Now, in the iTunes on the computer you want to transfer music to, select the library that you want to transfer music from, as per the following screenshot:
    Once the other library loads, go down to the bottom of the screen and in "Show:" select "Items not in my library":
    If you want to import all of the songs you can now see, head up to the iTunes menu bar and go "Edit > Select all". Then head down to the bottom of the screen again and click the "Import" button in the bottom-right-hand corner.
    If there's a lot of stuff in your original PC's library, the transfer may take some time.

  • How can I transfer work from one computer to another?

    How can I transfer work from one computer to another?

    Welcome to the forum.
    I can think of three basic ways to accomplish what you wish to do:
    Use the Project Archiver to archive your Project (and check the box to gather the media files), to an external HDD. Probably the easiest way to do it.
    Copy the Project and ALL media files to an external HDD, but be prepared to relink the media files to the Project, as the drive letter (part of the Absolute Path) will have changed.
    Edit loosely, and Share to an AV file, which will be Imported into a New Project on that second computer. Or, edit VERY tightly, and do the same. I like the first, as removing, replacing Transitions, etc., can be much more difficult, unless that "tight edit" is 100% done.
    Good luck,
    Hunt
    Message was edited by: Bill Hunt to correct formatting

  • How can I transfer information from one ipad to another?

    how can I transfer information from one ipad to another ?

    What kind of information? You can sync things like Contacts and Calendars by using iCloud. You can backup one iPad to iTunes on a computer and then sync the backup to the other iPad. You can configure your iTunes content and sync the same content to both iPads.
    It is based on what you want to do. Or are you looking for a way to send files from one iPad to another wirelessly? There are apps to do things like that, as well as cloud services, such as DropBox.

  • How can i transfer apps from one account to another.?

    now i had bought apps with my old account. but when i sync them into my phone i cant update them using my account, i need the old itunes i had. How can i transfer all bought apps onto my new account?

    You can't.
    All 3rd party apps - all paid and free apps include DRM protection which is tied to the iTunes account used to purchase/download the apps. DRM cannot be transferred from one account to another.
    Why did you get a new iTunes account? Changing your email address alone does not require doing so.

  • How can I move contact from one group to another?

    HOW CAN I MOVE A CONTACT FROM ONE GROUP TO ANOTHER GROUP?

    You usually make ​​contact groups via a computer (Mac or PC). If you use a mac and sync. via iCloud, you can go into Contacs.app and organize your contacts as you wish. Then (if) you sync with iCloud the groups you've changed or created will be displayed on your iPhone and (or) iPad.
    Hope this helped you.

  • How can I Move data from one column to another in my access table?

    I have two columns, one that stores current month’s data and one that stores last month’s data. Every month data from column 2 (this month’s data) needs to be moved to column 1 that holds last month’s data. I then null out column 2 so I can accumulates this month’s data.
    I understand how to drop a column or add a column, how do I transfer data from one column to another.
    Here is my trial code:
    <cfquery name="qQueryChangeColumnName" datasource="#dsn#">
      ALTER TABLE leaderboard
      UPDATE leaderboard SET  points2 = points3
    </cfquery>
    Unfortunately, I get the following error:
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in ALTER TABLE statement.
    How can I transfer my data with the alter table method?

    I looked up the Access SQL reference (which is probably a
    good place to start when having issues with Access SQL), and
    it suggests you probably need a WHERE clause in there.
    I agree the documentation is a good place to start. But you should not need a WHERE clause here.
    Too few parameters. Expected 1.
    If you run the SQL directly in Access, what are the results? At the very least, it should provide a more informative error message..

  • How can I migrate everything from one account to another on same computer?

    How can I migrate everything from one account to another on same computer?

    Transferring files from one User Account to another

Maybe you are looking for