How to stop the 2nd thread when 1st thread caught exception.

Hello Friends,
I have written a java program using Thread.
In this program i have created two separate threads.
For example Thread1 and Thread2.
During execution of both threads,
If any exception comes on Thread1 or Thread2, the other thread should not be continued its execution. Suddenly the other thread has to interrupted its execution.
How to do this. If any body know the way to do this, please help me.
Rgds
tskarthikeyan

Try this. It was working Fine.
public class ThreadComm {
     public static volatile boolean exceptionThrown= true;
     public static void main(String[] args) {
          Thread t1 = new Thread(new Runnable() {
               public void run () {
                    try {
                         /*if (exceptionThrown) {
                              System.out.println("First Thread Interrupted");
                              return;
                         for(int i=1;i<=5000;i++){
                              System.out.println("FirstThread>>"+i);
                              if(i==2500) {
                                   throw new Exception("First Thread Interrupted");
                    }catch(Exception e) {
                         exceptionThrown = false;
          Thread t2 = new Thread(new Runnable() {
               public void run() {
                    try {
                         /*if (exceptionThrown) {
                              System.out.println("Second Thread Interrupted");
                              return;
                         for(int i=1;i<=1000;i++){
                              System.out.println("SecondThread>>"+i);
                              if(i==777) {
                                   throw new Exception("Second Thread Interrupted");
                         int i=0;
                         while(exceptionThrown && i<=5000) {
                              System.out.println("SecondThread>>"+i);
                              if(i==4000) {
                                   throw new Exception("Second Thread Interrupted");
                              i++;
                    }catch(Exception e) {
                         exceptionThrown = true;
          t1.start();
          t2.start();
}

Similar Messages

  • Could somebody please advice how to stop the pages dropping ,when l go on ebay ,utube etc

    could somebody please advice how to stop the pages dropping ,when l go on ebay ,utube etc

    could somebody please advice how to stop the pages dropping ,when l go on ebay ,utube etc

  • How to Stop the method Action When an Exception Occur in other Method

    Hi All ,
    public void action( Event clientEvent) {
    startAction();
    JOptionPane.showMessageDialog(null, getDocumnetId());
    how to Stop the method action ( "action" ) if an exception occur in the method ("startAction")
    ( if the exception occur we doesn't need to show the JOption Message )

    Hi,
    try FacesContext.getCurrentInstance().renderResponse();
    Frank

  • How to stop the video buffering when video is paused

    Hi
    I am developing the video player with custom video controls and I want to stop the video buffering when my video is paused. As sson as I play the video the buffering starts from the last bufferring point.
    can any one please help me for doing this i searched lot but not getting the solution please help me out to sort out this.
    Please refer the following link that I want to create the progress bar for my video player.
    http://tv.adobe.com/watch/training-with-trani/shake-detection/
    Thanks
    Sameer

    Hi
        Here is the code i would tried bothe bufferTime and maxBufferTime but not getting the required output.
        please check the code below.
        var _videoInfo = new Object();
        _videoInfo.onMetaData = onMetaDataHandler;
        ns = new NetStream(nc);
        //ns.maxPauseBufferTime = 0;
        ns.client = _videoInfo;
        ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
        ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler);
        sndTransform = new SoundTransform(initVol);
        vid = new Video(stage.stageWidth,stage.stageHeight);
        vid.smoothing = true;
        videoCont.addChild(vid);
        vid.attachNetStream(ns);
        ns.play("video.flv");
        ns.soundTransform = sndTransform;
    Thanks

  • How to stop the Flex application when user clicks on Cancel button from JS-confirm message?

    Hi All,
    I use the next code when a user clicks on a link:
    private function clickHandler():void
          ExternalInterface.call('confirm', 'Of course you want to go to the Adobe forums!');
          navigateToURL(new URLRequest('http://forums.adobe.com'), '_self');
    This will show up the javascript confimation box. But when the cancel-button is clicked, the user goes straightly to http://forums.adobe.com...
    How to stop Flex performing the next code when a user clicks on the Cancel button?
    Or, how to catch which button is clicked by a user in Flex?
    Thanks!

    I agree with Mr. Hall that using mx.controls.Alert in Flex may be a better route.
    Show the Alert like this:
    // show an alert with a question and yes and no choices
    Alert.show( "Would you like to go to the Adobe Forums?", "Question",
         Alert.YES | Alert.NO, this, closeHandler, null, Alert.YES );
    Then handle the response in the closeHandler() function:
    protected function closeHandler( closeEvent:CloseEvent ):void
    if( event.detail == Alert.YES )
         navigateToURL( new URLRequest('http://forums.adobe.com'), '_self' );
    else if( event.detail == Alert.NO )
         // they chose no
    The following documentation on Alerts may be helpful:
    http://www.flexafterdark.com/docs/ActionScript-Alert
    Let me know if that helps...
    Ben Edwards

  • How to stop the 2nd screen processing from fristscreen

    Hi Friends,
    I have a problem in modulepool program, my user  wantsto display the information message in screen1
    without calling the 2nd screen.
    for example.
    user give the some input to screen fields, the system compare the what ever given inputs in screen1 is correct or not,
    incase the information is not correct, that time my user wants the information message,
    i wrote the information message in screen1 PAI, the message was displayed successfully but when i click the enter button the system calls the 2nd screen , what my user exact requirement is  system does not call the second screen, he want to shows the frist screen after getting the message.
    Can you please tell me solution.
    Thanks
    CHINNU

    instead of information message...use pop_to_confirm .....and remain in the same screen....
        CLEAR v_response.
        CALL FUNCTION 'POPUP_TO_CONFIRM'
             EXPORTING
                  titlebar              = 'Confirm Posting'
              text_question         = 'Do you want to Post Documents'
                text_question         = text_question
                  text_button_1         = 'Yes'
                  text_button_2         = 'No'
                  default_button        = '2'
                  display_cancel_button = ' '
                  start_column          = 25
                  start_row             = 6
             IMPORTING
                  answer                = v_response
             EXCEPTIONS
                  text_not_found        = 1
                  OTHERS                = 2.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
        CHECK v_response = '1'.
    Edited by: sugunav on Sep 8, 2009 6:04 PM

  • How to stop the "Read Reciept" when using messaging in the BI Process Chain

    Hey all - I set up a message in my process chain and now we get an email daily when that process finishes.  However it's asking for a read receipt from the users that it sends the message to.  I searched on this and also clicked on every button the message settings but could not find a way to turn off the read receipt request. 
    Does anyone know how to turn this off?

    HI,
    Go To
    1. SCOT   Tcode.
    2. Click on SETTINGS on the upper tab.
    3. Click on CONFIRMATION OF RECEIPT..
    4.and check the Radio button.. SAP  doesnot expectreceipt confirmation from internet..
    and click the tick button..
    Hope this helps u..
    Best Regards,
    VVenkat..

  • How to stop the iTunes launching when play/pause is pressed? PLEASE HELP

    I have a macbook pro 13 inches. When I play computer game, during an intense battle, I always accidently press the play/pause button.
    Immediately, the iTunes launch, which will make my game go frozen and I would always lose the battle. This make me extremely frustrated, I have lose so many battles cause of this problem. I know that I could turn the top row of my action keys to Fn keys. That would solve my problems, right? But no. Becuase I use those keys very often. It would be awful without them. For example, the screen brightness, the mission control, the keyboard back-lit light, the volume adjust. Without all these, my mac experience would be awful. Im just wondering if there are other solution beside for turning the Fn keys on.
    PLEASE HELP ME

    This has fixed it for me
    http://redth.codes/itunes-media-hotkey-disabler/

  • How to stop the black screen when opening firefox

    When I open a Firefox page it is just a black screen, no URL bar no Back, Forward or Home button nothing appears. After a couple minutes I can mouse over some stuff (mostly the blank spaces where you can enter text) and it will appear, but still can't see the "buttons" or menus (i.e.Internet options). Need to access the internet options to choose no proxy but I can't.

    May need to reinstall

  • How to stop the noisy screen when opening and closing?

    Whenever I open, close or adjust the angle of my laptop screen it makes an annoying creek and click sound. The sound usually varies whether its loud or faint.
    I think it's friction or something. Can I lube it up some way?
    Any suggestions?
    Thanks.
    Dorian

    Try a RadTech Glide Kit…
    http://www.radtech.us/Products/Glides.aspx

  • How to stop the NOTIFICATION prompt when any messa...

    (have belle)
    hey.... actually a few days back.. i gt a virus in my system.. so had to format my phone.. den took backup nd ol....
    bt aftr dat wenevr any call or message comes and i unlock my mobile its a big notification on my screen.. lyk d option wen we have to install something and we get option...
    "1 new message
     show... exit....     "
    i dun want dis option, coz pull down menu is gud enugh.. nd previously i dindn have it..
    its a small problem... but plz tell any1..  

    hellooooo...
    sm1 plz answer..
    i knw its nt worth ne1's tym... bt plz if u can tell..  

  • How to stop the thread?

    Hi,
    How to stop the thread in java. This is my program.
    import java.net.InetAddress;
    public class ThreadPing extends Thread {
         ThreadPing(String pingIP)
              super(pingIP);
              start();
         public void run()
              try
              String pingIP = Thread.currentThread().getName();
              InetAddress inet = InetAddress.getByName(pingIP);
              Boolean get=inet.isReachable(1500);          
              if(get==true)
                   System.out.println(inet.getHostName());               
              }catch(Exception e)
         public static void main(String args[])
              for(int i=1;i<=100;i++)
                   String pingIP = "192.168.1."+i;
                   ThreadPing tp = new ThreadPing(pingIP);
    Thanks in advance.

    The simplest way to stop all the thread is to make all thread daemons and exit the program when you want them to stop.

  • How to stop the prodution order creating when the product is not valued?

    Hi guyes:
    How to stop the prodution order creating when the product is not valued using CO01?
    I hope that when i create the production order,the system will check the product is valued or not,if not
    the system will show an error or warning message!
    How to config for this?
    Thank you!

    Dear Zhao Gang,
    Check with this user Exits mentioned in this link,
    Prevent Production Order from "Release" if there is no Cost Estimate
    Re: User Exit at Production Order Release
    Check and revert back.
    Regards
    Mangalraj.S

  • How to stop the option key from changing tools when trying to subtract from a selection?

    How to stop the option key from changing my tools when I am trying to subtract from a selection?
    I'm running CS3 on Mac OS Leopard, and the automatic tool switching slows me down, but even preferences doesn't show a way to turn this off.
    Thanks for your help.

    With any marquee tool, JUST holding down the option key should not switch tools. You need to explain the problem much more carefully, It's completely impossible to tell from your description whats going wrong.
    automatic tool switching
    The only preference related to this, is to do with the SHIFT KEY - "use Shift key for tool switch".

  • How to stop the dock from showing all hidden images when hiding then showing applications

    How to stop the dock from showing all hidden images when hiding then showing applications

    It's not really something to snap a screen shot of. I believe it would need to be a video clip. For instance, when I am working on multiple images in Photoshop, I often need many images open at the same time, but I only have one image viewable and active. The hero image is active on screen while I hide the other images in the dock by hitting the yellow - button on the images. Then I "Hide" Photoshop to do something in the Finder. When I go back to Photoshop, every image that is hidden in the dock will pop open again in the active window, not just the image I was currently working on. I want these images to stay in the dock until I need them, no matter how many times I Hide the Show Photoshop.

Maybe you are looking for

  • Button Enabled/Disabled linked to FormMode?

    Hi, I am new to SBO SDK and am in a learning as I go process having done basic training. I am adding a button to the business partners page. The new button I need 'greyed out' "oForm.Items.Item("oBtn1").Enabled = False" when the form mode is add or f

  • Oracle VM 3.1 into VirtualBox how-to

    I'm trying for a testing to install latest Oracle VM release into VirtualBox. Host: VirtualBOX 4.1.16 Guests: Oracle VM Manger (3.1.1) Guests: Oracle VM Server (3.1.1) Guests: Oracle VM Server (3.1.1) Can I simulate a shared storage between the two V

  • How to delete unwanted iphotos? (not edited originals)

    How can I delete unwanted photos in iphoto? I don't care about deleting originals that I have been edited, I want to remove trash shots from my computer while working in iPhoto. So is there a way to delete photos from DB, w/o going into the finder. I

  • IDVD "stretches" my movie -using PanasonicHDC-SD1. Best workflow?

    OK, trying to find the best overall workflow for the best movies burned via iDVD. Here's what I tried: Using the HD cam, importing to iMovie 08, and "Sharing" using Quicktime, then picking the codec "Apple Intermediate", size is 1280x720. This gave m

  • Magic mouse not working with mountain lion

    Hey is anyone else loosing connection with their magicmouse since the mountain lion release... I have had three sets of new batteries and it still keeps losing connection. Can anyone else help me?