Common practice to stop thread - checking flag or checking interrupt status

Hello all, from the official document from Sun http://java.sun.com/j2se/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html , I was understand that the common practice to stop a thread is to
   private class StockMonitor extends Thread {
        public StockMonitor() {
            thread = this;
        public void run() {
            final Thread thisThread = Thread.currentThread();
            while(thisThread == thread) {
        public void _stop() {
            thread = null;
        private volatile Thread thread;
    }However, the need to have an extra flag is rather cumbersome. Hence, is it a common practice which we can stop a thread by checking its interrupt status? What is the pros and cons of the two methods?
Thanks
    private class StockMonitor extends Thread {
        public StockMonitor() {
            thread = this;
        public void run() {
            final Thread thisThread = Thread.currentThread();
            while(thisThread.isInterrupted()) {
        public void _stop() {
            interrupt();
    }

However, I thought checking thisThread.isInterrupted() is enough? As the following case...
public void run()
    while(Thred.currentThread().isInterrupted())
        // Do something
        try {
            Thread.sleep(1000);
        catch(InterruptedException exp) {
            // Must break while loop from here. This is because interrupted
            // flag had been reset. If not, we will not able to
            // exit this while loop.
            break;
    }So, is there any need for a boolean type status flag? Can you please provide me any case, where it is impossible to achieve by just using checking thisThread.isInterrupted() checking?
Message was edited by:
KwangHooi

Similar Messages

  • How to check the value of "The Interrupt Status Flag"?

    Hi, thank you for reading this post!
    Invoking Thread.interrupt() sets the value of the Interrupt Status Flag.
    Just wondering if there is a Java method to check the value of this flag? Or is using isInterrupted() or interrupted() the only way to check?
    http://download.oracle.com/javase/tutorial/essential/concurrency/interrupt.html
    Thank you in advance for your help!
    Eric

    Below is the full code. As soon as the Thread.sleep() is taken out in main(), the interrupt is detected in the child thread. But if the sleep() stays, then the child thread goes into an infinite loop. It's not detected the interrupt.
    //ParentInterruptChildThreadCatchedDemo.java
    //Program function: This program demonstrates the parent thread (main()) interrupting a child thread (thread1).
    //Threaded class
    class TryThread extends Thread {
         //fields
         private String threadname;
         private long aWhile;
         //Constructor
         public TryThread(String tname, long delay) {
              threadname = tname;
              aWhile = delay;
         //run() method
         public void run() {
              while(!Thread.interrupted()) {
                   //Do work
              try {
                   System.out.println(Thread.currentThread().getName() + " was just interrupted!");
                   throw new InterruptedException();
              } catch(InterruptedException e) {
                   //System.exit(1);
                   return;
    public class ParentInterruptChildThreadCatchedDemo {
         public static void main(String[] args) {
              Thread thread1 = new TryThread("thread1", 2000L);
              thread1.start();
              try {
                   System.out.println("main() goes to sleep for 10 second.");
                   Thread.sleep(10000);
                   System.out.println("Statement after main() sleep().");
              } catch(InterruptedException e) {
                    e.printStackTrace();
                 //Interrupt thread1
                  int interruptFlag = 5;
                  for(int i=0; i<11; i++) {
                       if(i == interruptFlag) {
                            System.out.println("Condition met, going to interrupt thread1 ...");
                            thread1.interrupt();
                            System.out.println("Thread1 interrupted!");
                  System.out.println("Ending main()");
    /*Output:
    main() goes to sleep for 10 second.
    Statement after main() sleep().
    Condition met, going to interrupt thread1 ...
    Thread1 interrupted!
    Ending main()
    INFINITION LOOP
    */

  • How to GR for PO in which delivery completion flag is checked.

    How can I stop GR against a PO in which Delivery Completion Flag is checked for the line item.

    To stop the system from proposing a quantity in Transactions MB01 or MIGO and to prevent a GR posting, you can proceed as follows:
    Reduce the purchase order quantity to the previous GR quantity.
    Block the purchase order item.
    (ME22N: Block pushbutton; ME22 Menu -> Edit -> Block)
    Fill the date field for the 'Latest Possible Goods Receipt' (LEWED) in the purchase order item. If you do this and you enter a GR document after this date, the system issues message M7163, which you must set as an error message in Customizing.
    see OSS Note 856279 - MIGO: Proposed qty despite 'delivery completed' indicator
    By the way, setting the block is not really recommended and jsut short term solution, as it will stop you from archiving this PO

  • Stopping threads

    how to stop threads immediately?following is my threading code.when i press the stop button the game stops after one or more generations (John Conway's life game).i have tried the boolean solution i.e. declaring a boolean variable and setting it true or false to start and stop the game.is there a more powerful method than yield to stop the thread?how to solve this problem?
    private Thread lifeThread=null;
    //this is the code used when the start button is pressed
    public void start() {
    if(lifeThread == null)
    lifeThread = new Thread(this);
    lifeThread.start();
    //this is the code for the stop button
    public void stop() {
    if(lifeThread != null)
    lifeThread.yield();
    lifeThread = null;
    //run method
    public void run() {
    while (lifeThread!=null) {
    next();
    gen_num++;
    repaint();
    try {
    lifeThread.sleep( delay );
    } catch (InterruptedException e){}

    no.....thread.stop() is not a good read for your question....ignore the last poster.
    You have the right idea...you simply need to set your boolean in a finer grained way. If you are in a long loop, then you should be checking that boolean value at the top of your loop so you can drop out of the loop immediately when the user requests to stop it.
    So again, right idea, you just need a minor logic change.

  • Is it common practice for Verizon to park in a private driveway to perform services?

    A verizon Vehicle with the plate {edited for privacy} parked in one of my parking spaces for approximatley 4 hours today (he's still there as I'm typing this). Is it common practice for a represenative to park in another person's private driveawy to perform services for other consumers? 
    My son had no where to park, and he's still waiting for your rep to leave. 
    I want to file a complaint against this worker. 
    I can't even speak with him or her because they aren't in their car. 
    Is Verizon above the law? Can you guys just legally park whereever you want to? Serious question, maybe there's something you know that I don't.

    Your issue has been escalated to a Verizon agent. Before the agent can begin assisting you, they will need to collect further information from you.Please go to your profile page for the forum, and look in the middle, right at the top where you will find an area titled "My Support Cases". You can reach your profile page by clicking on your name beside your post, or at the top left of this page underneath the title of the board.
    Under “My Support Cases” you will find a link to the private board where you and the agent may exchange information. This should be checked on a frequent basis as the agent may be waiting for information from you before they can proceed with any actions. To ensure you know when they have responded to you, at the top of your support case there is a drop down menu for support case options. Open that and choose "subscribe".
    Please keep all correspondence regarding your issue in the private support portal.

  • Stopping thread with timeout using threadpool

    Is there any way to set thread timeout within Executor.newFixedThreadPool ? I have a long queue around 5M which is creating with:
    ExecutorService executor = Executors.newFixedThreadPool(500);
    total = 10000;
    while (totalRows > 0) {
                    localStatement.executeQuery("SELECT domainID, domain FROM com WHERE status = '' LIMIT " + total);
                    totalRows -= total;
                    localResultSet = localStatement.getResultSet();
                    while (localResultSet.next()) {
                        HttpGet httpget = new HttpGet("http://" + localResultSet.getString("domain").toLowerCase());
                        executor.submit(new GetThread(httpClient, httpget, localResultSet.getInt("domainID")));
                    Thread.sleep(1000);
                    while (((ThreadPoolExecutor) executor).getActiveCount() > 10) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                    localResultSet.close();
                    System.out.println("New cycle");
                }But sometimes threads lock and cycle can't finish. Is there anyway to stop thread after N seconds? I can encapsulate Runnable into another Runnable and stop it from there, but it doubles threads, and I believe its not a good way.

    yes, you need at least one more thread. you could use one thread to monitor multiple other threads, but you need at least one more thread to wake up after the timeout and check on/cancel the main task.

  • How to populate tax area for IT 207? what is the common practice?

    Gurus,
    How to populate tax area for IT 207? what is the common practice?
    The residential address IT 0006 is a new your address with ZIP code 10001
    PA30 for IT 207 displays 4 tax areas for the new york address.
    FED     Federal     0000-0001       99999-9999
    NY     State of New York             14999-9999
    NY01     New York City          14999-9999
    NY02     Yonkers                   14999-9999
    I thought, each zip code will map to only one tax area.
    Thanks,

    This is the real world ! SAP does not design tax area based on zip codes. In our company, the tax lady calls the tax authorities to check what zip codes fall under that tax authorities.
    and BTW, with new BSI upgrade, you will find 12 more tax authorities for NY.
    Cheers !!!!
    W

  • System Error in Message Monitoring while it shows checked flag in SXMB_MONI

    Hia,
    We are working on ABAP Proxy --> SAP PI 7.1 --> SOAP (Asynchronous Scenario).
    (ECC -> PI -> Legacy CRM)
    I have following queries:
    1. While sending messge across to Legacy system, we can see CHECKED flag in SXMB_MONI but there is System Error in Message Monitoring. When checked legacy system is unable to receive any message. Cannot understand the issue.
    2. Is there any way to check in PI system whether the message has reached Legacy System other than making scneario synchronous?
    Regards

    System is getting connected and able to send asynchronous messages to legacy system. But getting following error while sending synchronous error:
    2010-05-10 13:15:05     Information     Delivering to channel: CC_SOAP_SOReject_Out
    2010-05-10 13:15:05     Information     SOAP: request message entering the adapter with user J2EE_GUEST
    2010-05-10 13:15:05     Information     SOAP: completed the processing
    2010-05-10 13:15:05     Information     SOAP: continuing to response message f33caa90-5c07-11df-c659-96d147c2ff0f
    2010-05-10 13:15:05     Error     SOAP: response message contains an error XIAdapter/PARSING/ADAPTER.SOAP_EXCEPTION - soap fault: Server was unable to process request. ---> Object reference not set to an instance of an object.
    2010-05-10 13:15:05     Error     Adapter Framework caught exception: SOAP: response message contains an error XIAdapter/PARSING/ADAPTER.SOAP_EXCEPTION - soap fault: Server was unable to process request. ---> Object reference not set to an instance of an object.
    2010-05-10 13:15:05     Error     Delivering the message to the application using connection SOAP_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: SOAP: response message contains an error XIAdapter/PARSING/ADAPTER.SOAP_EXCEPTION - soap fault: Server was unable to process request. ---> Object reference not set to an instance of an object.. Setting message to status failed.
    2010-05-10 13:15:06     Error     The message status was set to FAIL.
    I have already checked Data Structure and it is fine.
    Regards
    In this scenarios we are using XSLT mapping using CDATA.
    Please suggest solution.

  • I get a message that itunes  has stopped working. When I check out why it is because of the dep security on my computer. When I try to find the program for itunes for the .exe file i cannot find it to turn off the dep for  that file

    I get a message that itunes  has stopped working. When I check out why it is because of the dep security on my computer. When I try to find the program for itunes for the .exe file i cannot find it to turn off the dep for  that file

    I found the file but when I added it to the  list for the Data  Execution Program to ignore , I received a message that the Program.x86/itunes file must have the DEP on in order to run. Anyone else having this problem ?

  • Check flag for double invoices in AR masterdata

    Hello all,
    Can you please tell me if there is any flag in AR masterdata transaction FD01 similar with the one in AP masterdata transaction FK01 - "check flag for double inv.".?
    Thank you,
    Daniel

    For customer, there is no such mechanism. There is NO TICK in customer for duplicate invoice.
    It is not required because the amount is incoming, where in case of customer the amount will be outgoing.
    Regards,
    Ravi

  • Check Flag for Double Invoices or Credit Memos

    hello
    can i one please explain me the effect of
    "Check Flag for Double Invoices or Credit Memos"
    please explain with explain
    thanks
    vijay

    as terms itself says that u can post the same invoice twice it helps u in posting the same invoice twice
    suppose u have post invoice 1103#
    now by mistake user trys to enter the sam e invoice to release the payment then system dispalys a messge wrning or error
    but to activate it u need to do the settings in spro-mminvoice---incoming invoice
    and mark the check box in vendor master

  • AS2 common practices and party definitions

    Dear reader,
    I've a question about AS2 identifiers and common practices as is explained in more detail below:
    <b>Context</b>
    We have implemented Seeburger AS2 adapter on SAP XI.
    In our SAP XI environment we have depict parties in SAP R/3 (customers vendors etc) in SAP XI as well to enable clear depiction of message flows.
    For large companies we may find several SAP XI parties because the company may have and an office in Canada and an office in the US. (These are two parties in the SAP R/3 system as well)
    The company uses <u>one</u> AS2 server to communicate.
    Seeburger AS2 adapter allows <u>one</u> AS2 identifier to be defined for <u>one</u> SAP XI party. It is not possible to define the same AS2 identifier for two SAP XI parties.
    <b>Questions</b>
    Is it common practice for large company to use <u>one</u> AS2 identifier for all their offices? Can we expect to have <u>several</u> AS2 identifiers, one per office?
    If large companies only use one AS2 identifier is it wise to introduce a new SAP XI party specifically for AS2 communications and tigh the AS2 identifier to this party?
    Note the questions above only apply to inbound processing. For outbound processing the sender and receiver party (AS2 identifier) can be set using a header map in an receiver agreement.
    Your help is appriciated.
    Best Regards,
    Harald Kastelijn
    Message was edited by:
            Harald Kastelijn

    Harald,
    I think that the best way is to create different services for every division under the party (company) with multiple divisions. (Exp. for Party BMW you can have services BMW_DE and BMW_USA). AS2 ID is unique and even for large companies (if they have one IT department) is possible using of the same AS2 ID.
    Regards
    Naycho

  • FK02 - Check Flag for Double Invoices or Credit Memos

    Hi,
    What is the transaction in customizing to set the parameters for check flag for double invoices or credit memos ? (ex: date, reference number, etc.) (so that a warning message will pop-up if  user tries to do such a transaction 2 times)
    The check box check double inv. is already cheked in FK02, but I want to set the different parameters.
    Julien

    OMRDC

  • Common Practice For Storing Application Data Files

    During my application development targeting for XP and Linux time, I will store my application data files (Files where user may create, modify, rename, delete...) same path as my application directory. For instance, if my application is installed in :-
    C:\Program Files\MyApp\MyApp.jar
    All my application data files will be located in
    C:\Program Files\MyApp\Config\ directory.
    This works quite well until Vista introduce UAC. Vista will not allow write opration to C:\Program Files\MyApp\Config\ folder (Config folder is being created during installer execution). However, to support legacy application, Vista use a workaround (Virtualization) for application to write. For example, MyApp.jar want to perform write on
    Real path :-
    C:\Program Files\MyApp\Config
    Vista will redirect it to :-
    Virtual path
    C:\Users\<account>\AppData\Local\VirtualStore\Program Files\MyApp\Config
    Please refer to the links for more detail
    [http://www.codeproject.com/KB/security/acl_common_data.aspx?display=Print]
    [http://www.codeproject.com/KB/vista-security/MakingAppsUACAware.aspx]
    However, this introduce several additional problems [http://support.microsoft.com/kb/927387]
    May I know what is the common practice for storing an application data files? The below are my several thoughts
    (1) Writing to
    * Windows XP - %systemdrive%\Documents and Settings\All Users\Application Data
    * Windows Vista - %systemdrive%\ProgramData
    * Windows 2000 - %systemdrive%\Documents and Settings\All Users\Application Data
    * Windows Server 2003 - %systemdrive%\Documents and Settings\All Users\Application Data
    * Windows 98 - %systemdrive%\Windows\All Users\ Application Data
    which we may retrieve through "CommonApplicationData", using the API function SHGetFolderPath. However, how can we do that in Java? How to make compatible with Linux?
    (2) Writing to user home directory through "user.home" properties. Create a folder .MyApp and write the application data on it.
    Any input and suggestion are welcomed.
    Thanks!
    cheok

    >
    ...I will store my application data files (Files where user may create, modify, rename, delete...) same path as my application directory. >See [Store Application Settings and Components|http://sdnshare.sun.com/view.jsp?id=2305] for code that will put the required parts in a suitable sub-dir of user.home.

  • Runtime Error-Description of Exception in Moni with Checked Flag

    Hi Floks,
    I am working on one interface ABAP proxy to File.While Executing the interface i am getting checked Flag in the Moni but when i double clicked on it.Its Displaying an error message.The error message is displaying like *Runtime Error-Description of Exception*
    *Under that the Short text is The Current application Triggered a termination with a Short Dump*.But I am getting the proper Out put.
    Please do needfull help on this.
    Regards,
    sai

    Hi,
    In error analysis iam getting this can u
    Error analysis
        Short text of error message:
        Control Framework : Error processing control
        Long text of error message:
         Diagnosis
             An error occurred when the system tried to process the comma
             from the Automation Queue on the presentation server.
             There are several possible reasons for this:
             - The installation of the SAP GUI on the presentation server
             faulty or obsolete.
             - There is an error in the application program
             - There is an error in the SAPGUI or an integrated control
         Procedure
             1. Make sure that you have imported the appropriate Support
             Package, the current kernel, and GUI patch for the release o
             system
             2. Check whether the error occurs locally on one or a few PC
             generally on all PCs. Note whether the error only occurs for
             users, for example because of a specific Customizing setting
             If it only occurs locally, this suggests an installation pro
             with the PC. Check the installation; if necessary, reinstall
             software. In the dump, search for the SY-MSGLI field, since
             point to the cause of the error.
             3. Activate the Automation Trace (in accordance with SAP Not
             158985).
             4.Start the transaction and continue until the screen immedi
             before the dump.
             5. From the System -> Utilities menu, choose Autom. Queue,
                      Synchronous Processing.
             The status bar of the GUI displays the text:
                "Automation synchron flush mode on"
             6. If you now proceed with the application, the short dump will
             display the ABAP call that caused the error; the Automation Trace
             will contain the error on the presentation server.
             7. If necessary, load the short dump and trace files on to
             sapservX, so that SAP can analyze them.
        Technical information about the message:
        Message class....... "CNDP"
        Number.............. 006
        Variable 1.......... " "
        Variable 2.......... " "
        Variable 3.......... " "
        Variable 4.......... " "
    this message i am getting so can u plazzzzz

Maybe you are looking for

  • Why can I no longer search a specific forum?

    It doesn't seem that long ago that one could drill down in the technical discussion forums and then search a specific forum.  Now, all I can see is that, no matter what forum I navigate to, I can only enter search terms for the entire "community".  9

  • Add selected value to holding table

    hi i have a situation where i search user from the table,and go and add those selected user in OID,But now before i add those user to OID i what to add tham in holding table not database table, where i can see all user i have selected,and have a chec

  • Configure a Password Policy

    Hi All, i want to have a password policy for the database. As I found, there's a default table called dba_profiles where we can set password properties for the default database profile in 11g. Actual requirement is to change the sys user's password i

  • What happened?!  I moved and now software won't read my MIDI controller?

    Exactly that. I moved and when I put together my computer, Mbox2, and Korg MIDI controller none of the software will read it!?!! I went to Reason and Logic and they both say check your device and/or connection. Can't detect anything. MIDI cable works

  • FTPS/Implicit SSL connections filter

    BorderManager 3.8 on NetWare 5.1 - I have plenty of successful ftp-port-pasv-st exceptions that I use, but now I need one for an FTPS/Implicit SSL connection, which *should* user port 990. But when I define an exception (creating a new packet type, T