Using wait or sleep without a thread

Is there any method to do the equivalent of a wait or sleep without using threads?

You have a single-threaded application executing, and
you want to pause it at a given location for a given
period of time. If you call sleep, you give up
execution, which you don't want to do.What do you mean by not wanting to give "up execution"? It is the scheduler of your OS that decides when your program executes or not. Your code snippet does nothing but burn processor time (incidently pretending to the scheduler that it actually has something useful to do) which could be well used by some other process running on the computer. Use Thread.sleep instead, thats what it is there for. If you want to somehow affect the amount of processor time that the scheduler allocates to your process you will be better served by increasing its priority.
having my skill and/or intelligence mocked Well, I have certainly not mocked your skill nor your intelligence, god knows that I have on occasion presented poor solutions in this and other forums, but lets not dwell on that...

Similar Messages

  • BAPI commit without using Wait? need to get the data for created order

    I am using BAPI to create or change sales order and by using 'BAPI_TRANSACTION_COMMIT' updating the database.
    Immediately after that there is some requirement to fetch VBAP with the created order number, but there is no data found.
    If i use call function 'BAPI_TRANSACTION_COMMIT'
                 exporting
                   wait          =  'X'.
    then i am able to fetch data from VBAP, but its impacting the performance. Is there any alternative way to get data without fetching or without using wait.
    Can i use ABAP memory or SAP memory to get the details?
    Please help...........

    Hi Tapas379,
    Yes technically you can:
    set data before commit
    DATA memory_id(20) TYPE c.
      CONCATENATE 'VBAP_01_' sy-uname INTO memory_id.
      DELETE FROM DATABASE indx(as) ID memory_id.
      EXPORT vbap_tab = vbap_tab "<-input
        TO DATABASE indx(as)
        CLIENT sy-mandt
        ID memory_id.
    Get data from anywhere after setting it.
      data memory_id(20) type c.
      concatenate 'VBAP_01_' sy-uname into memory_id.
      import vbap_tab = vbap_tab " ->output
        from database indx(as)
        client sy-mandt
        id memory_id.
      delete from database indx(as) id memory_id.
    Thanks,
    Duy

  • Topic about wait(),join(),sleep() and yield()

    Hi there,
    I'm headache with the implementation of wait()��join()�� sleep() yield(). Can anybody tell me:
    1. what's the difference between wait() and join(), I can't see it.
    2. As I know if thread A waits on thread B then A will release the lock. How about join, or slepp, or yield?
    3. Why use notify()? As I see if thread A waits on thread B, when B completed without calling notify(), the A will continue its job!!
    thanks thanks thanks

    1. Object.wait() will make a thread wait until Object.notify() is called on the object. Thread.join() will make the running thread to wait until the thread object finish to execute.
    2. .wait() does not wait on thread, it wait on objects. .sleep(long timeout) is about the same as .wait(long timeout), except that it need to be awaken with a .interrupt, not .notify. Also you cannot awaken more than one thread with a .interrupt, while a call to .notifyAll() will awaken all threads waiting on that object. .yield() suspend the current thread only to give a chance to others thread to execute and the initial thread will continue ot execute only a hort time after the .yield().
    3. See #1, #2 and think a bit.
    Regards

  • Difference between wait() and sleep()

    hi
    can any one tell me what is the difference between wait() and sleep().
    thanks in advance.

    Mahaboob,
    This question has been asked before; however, I will give you a real life example.
    Imagine you are in a super market and you go to the till to pay by your card, then behind you there are 10 people waiting in queue. You card does not work since you have not supplied the right pin code; there are two option
    1- Sleep
    2- Wait
    1- If you sleep you will lock the till for your self and try to figure out the pin number while the queue behind you increase on the resource (till)
    so you are engaging the till and wasting its time and wasting the till machine resource (CPU)
    2- you are polite, you move aside and wait so so that others can use the resource (till) until somebody in the queue finishes ( a good person) and give you a shout to tell you come in to the till to process your payment; you wake up and enter the pin number and go out from the super market.
    Now when you sleep, the current thread locks the resource so no body can use it and wast the CPU time
    while wait make the current thread release the lock on the object and does not ( this thread) actually wast the CPU time
    There are much more explanantion, try to search this forum.
    Regards,
    Alan Mehio
    London,UK

  • Use a Zen Micro without the batt

    hello, i would like to know if there is any way to use a zen micro without the battery inserted via usb cable, because i have a 6gb micro that i don't use, the battery died, and i would like to connect it to my amplifier, but all the micros i have came without the power adapter,wich would work. My computer's motherboard suplies power trhough usb even when the pc is off, so i woudn't even had to turn it on to hear music, but, unfortunely, micro's don't work without battery when plugged to the usb cord, right?. i like to know if i can tweak something in the micro to do this...please help me...

    It remembers as long as it has power. This kind of thing has been discussed before, but not in this situation, but it's still the same....
    If you unplug your Micro before it's gone into it's deep sleep slumber mode, then it will forget, and start back from it's LAST deep sleep mode. However, if you let it go into the deep sleep mode, then you can unplug it, and put your battery into it, and it will be at the same point it was when you just turned it off.
    (by the way, not to thread jack, but this is my 50st post. Wow).

  • Wait or sleep?

    Hi,
    I am at University doing Java. My new assignment is multithreading in a Windows Application.
    So,
    I have created 2 threads (one with just a string and the other making a sound (wav file)).
    My problem now is ...
    I want the window to open first, then for the words to show up on the window, AND THEN the sound. Now I want the sound to be done in 3 consecutive times.
    In other words:
    1st: fT
    2nd: s1T
    3rd: s2T
    4th: s3T
    Basically here is what I did:
    import java.awt.*;
    import java.awt.event.*;
    public class WindowsAppli extends Frame {
        TextArea outArea = new TextArea("Incoming call ...\n");
         T1 firstT = new T1();
         T2 second1T = new T2();
        T2 second2T = new T2();
        T2 second3T = new T2();
            public WindowsAppli ()
           add(outArea);
           setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15));
           Thread fT = new Thread(firstT);
           fT.start();
           try
              Thread.currentThread().sleep(10000);
           catch (InterruptedException e)
          outArea.append(firstT.res);
          Thread s1T = new Thread(second1T);
          Thread s2T = new Thread(second2T);
          Thread s3T = new Thread(second3T);
          s1T.start();
          s2T.start();
          s3T.start();
        public static void main(String[] args)
            Frame f = new WindowsAppli();
             f.setTitle("Windows Application");
              f.setSize(600,400);
              f.setVisible(true);
             f.addWindowListener (new WindowAdapter ()
                public void windowClosing(WindowEvent e)
                     System.exit(0);
    }Any help please?

    If you want to wait for some even to occur, use wait, and a corresponding notifyAll(), or the higher level scheduling tools in java.util.concurrent.
    If you want to pause for a fixed amount of time, use sleep, although if you're doing that in a loop, you may want java.util.Timer and TimerTask.

  • Wait() vs sleep()

    This is a purely general question, I was wondering which is better to use: sleep() or wait()?

    Use sleep() if you just want to wait for some time,
    for example if you want to wait before you retry to
    create a socket connection when the first try failed.
    This is wrong. Never use sleep when you are using synchronization, it could cause deadlocks. Instead, use wait as wait will release all your locks and thus reduce the chance of deadlock. Remember that your thread may be holding locks that you are unaware of so it's best to wait (not sleep).
    Use wait() if you want to synchronize multiple
    threads, for examplw when one thread has to wait for
    the resutl of another thread. >
    So fi you have only one thread ( and i assume that
    have you never written a multithreaded app) just use
    sleep() adn forget wait(). They might look similar but
    serve quite different purposes.
    Java is multithreaded by nature, it's impossible to write a non-multithreaded application in java as there are at least a few threads ( finalizer thread, GC thread, your main thread). And any non-trivial java program will have at least 2 threads. Any java application that uses swing has at least 7 threads. So you must expect that your code will be run in multiple threads and thus sleep is not a good choice.
    I don't think that using sleep should be recomended because it doesn't release locks.

  • How do I use my wireless Led TV as a second monitor using my home network without any cables? Both of them are connected to home network

    How do I use my wireless Led TV as a second monitor to my mac book pro using my home network without any cables? Both of them are connected to home network

    Having a gateway there is not going to be a problem. We just need to configure the Time Capsule correctly to work with the 2Wire.
    You will need one ethernet cable to connect the 2Wire to the Time Capsule and a second ethernet cable to temporarily connect your computer to the Time Capsule so that it can be configured.
    The 2Wire you have now should already be broadcasting a wireless network, so once you have the Time Capsule setup, you will actually have two wireless networks there.
    Here's how to configure the Time Capsule to work with the 2Wire:
    Connect an ethernet cable from one of the LAN <-> ports on the 2Wire to the WAN (circle icon) port on the Time Capsule.
    Connect another ethernet cable temporarily from your computer to one of the LAN <-> ports on the Time Capsule
    Open Hard Drive > Applications > Utilities > AirPort Utility
    Click Manual Setup
    Click the Base Station tab below the row of icons to assign a name for the Time Capsule, a device password (write this down) and adjust time zone settings
    Click the Wireless tab below the row of icons
    Wireless Mode....Create a wireless network
    Wireless Network Name....Your choice
    Radio Mode....Automatic
    Channel...Automatic
    Wireless Security...WPA/WPA2 Personal
    Wireless Password....Your choice (write this down)
    Check mark next to....Remember password in keychain
    Click the Internet icon
    At the bottom, change the setting for Connection Sharing to "Off (Bridge Mode)"
    Click Update at the lower right and the Time Capsule will restart after 20-25 seconds and you should get the green light.
    You should now be able to connect to your Time Capsule wireless network.
    I'm not clear on whether you have tried to setup the Time Capsule to backup your computer. Post back if you need some info on that. We may need to start another thread for that as that will be a different subject.

  • How to use wait/nofity in socket server

    Dear all
    that is one of sample code from a book which's use mutil connection with socket program , but i if it is possible to use wait and nofity to controle client activety by wait and notify in this sample code ?
    some idea hope someone give me a help please
    import java.net.*;
    import java.io.*;
    * Threaded Echo Server, pre-allocation scheme.
    * Each Thread waits in its accept() call for a connection; this synchronizes
    * on the serversocket when calling its accept() method.
    * @author Ian F. Darwin.
    public class EchoServerThreaded2 {
         public static final int ECHOPORT = 7;
         public static final int NUM_THREADS = 4;
         /** Main method, to start the servers. */
         public static void main(String[] av)
              new EchoServerThreaded2(ECHOPORT, NUM_THREADS);
         /** Constructor */
         public EchoServerThreaded2(int port, int numThreads)
              ServerSocket servSock;
              Socket clientSocket;
              try {
                   servSock = new ServerSocket(ECHOPORT);
              } catch(IOException e) {
                   /* Crash the server if IO fails. Something bad has happened */
                   System.err.println("Could not create ServerSocket " + e);
                   System.exit(1);
                   return;     /*NOTREACHED*/
              // Create a series of threads and start them.
              for (int i=0; i<numThreads; i++) {
                   new Thread(new Handler(servSock, i)).start();
         /** A Thread subclass to handle one client conversation. */
         class Handler extends Thread {
              ServerSocket servSock;
              int threadNumber;
              /** Construct a Handler. */
              Handler(ServerSocket s, int i) {
                   super();
                   servSock = s;
                   threadNumber = i;
                   setName("Thread " + threadNumber);
              public void run()
                   /* Wait for a connection. Synchronized on the ServerSocket
                    * while calling its accept() method. */
                   while (true){
                        try {
                             System.out.println( getName() + " waiting");
                             Socket clientSocket;
                             // Wait here for the next connection.
                             synchronized(servSock) {
                                  clientSocket = servSock.accept();
                             System.out.println(getName() + " starting, IP=" +
                                  clientSocket.getInetAddress());
                             DataInputStream is = new DataInputStream(
                                  clientSocket.getInputStream());
                             PrintStream os = new PrintStream(
                                  clientSocket.getOutputStream(), true);
                             String line;
                             while ((line = is.readLine()) != null) {
                                  os.print(line + "\r\n");
                                  os.flush();
                             System.out.println(getName() + " ENDED ");
                             clientSocket.close();
                        } catch (IOException ex) {
                             System.out.println(getName() + ": IO Error on socket " + ex);
                             return;
    }if i add end of my code like this and then the error message indicat that
    java.lang.IllegalMonitorStateException: current thread not owner
    try{
                        clientSocket.wait();
                 }catch(InterruptedException e){
                                              clientSocket.close();
                                              clientSocket.notify();
                                            }

    Why? Closing the socket will cause the client to return from reading the socket with a null or zero or EOFException. You don't need anything else.
    In any case notifying the clientSocket will only wakeup threads in the current JVM that are waiting on it. This mechanism isn't magic, and it can't wake up another JVM.

  • Is it possible to run Posture using ISE 1.2 without NAC Agent provisioning?

    Is it possible to run Posture using ISE 1.2 without NAC Agent provisioning?
    -My customer does not want to push NAC Agent installation on BYOD type of computers (non-managed by the company computers).
    -The requirement is to check for posture only company owned wired, wireless, and VPN connected Windows computers. The rest of the endpoints should be considered as posture incompliant, and limited access to the network should be allowed.
    -No certificates are used.
    -I’ve configured the required posture check, and it all works fine if a PC has NAC Agent manually installed (without ISE Client Provisioning). However, when I use a PC without NAC Agent, it is redirected to Client Provisioning Portal and is stuck there as Client Provisioning is deliberately not configured in ISE.
    -If I remove Posture Remediation Authorization Profile that does URL redirect, the posture does not work.
    -For now I'm testing it on wired endpoints.
    Is there a way to configure ISE to fulfill the listed above requirements?
    Any ideas would be appreciated.
    Thanks,
    Val Rodionov

    Everyone who finds reads this article,
    I'm answering my own quesiton "Is it possible to run Posture using ISE 1.2 without NAC Agent provisioning?"
    The answer is Yes.
    After doing research and configuration testing I came up with a solution, and it works fine for wired and VPN connections. I expect it to work on wireless endpoints as well.
    ISE configuration:
    Posture General Settings - Default Posture Status = NonCompliant
    Client Provisioning Policy - no rules defined
    Posture Policy - configured per requirements
    Client Provisioning (under Administration > Settings) - Enable Provisioning = Enable (it was disabled in my first test)
    Authorization Policies configured as regular posture policies
    The result:
    After successful dot1x authentication posture redirect happens. If the PC does not have NAC Agent preinstalled, the browser is redirected to Client Provisioning Portal and a default ISE message is displayed (ISE is not able to apply and access policy... wait one minute and try to connect again...). At the same time, the endpoint is assigned NonCompliant posture status and proper authorization policy is applied. This is what I wanted to achieve.
    If NAC Agent was preinstalled on the PC, after successful dot1x authentication the NAC Agent pops up and performs posture check. If posture is successful, posture compliant authorization policy is applied. If posture check fails, NonCompliant posture status is assigned and posture non-compliant authorization policy is applied. Which is the expected and needed result.
    The only part that is not perfect it the message displayed to the end-user when posture is about to fail. I did not find a place to change the text of that message. I might need to open TAC case, so this file can be manually found and edited from CLI (root access).
    Best,
    Val Rodionov

  • G41m p28 Sleep without fan ?

    I can't get my PC to sleep under Win7; the fan stays on.
    The manual says:
    if the mainboard has a System Hardware Monitor chipset on-board, you must use a specially designed fan with speed sensor to take advantage
    of the CPu fan control.
    I've checked the 4-pin CPUFAN and the control pin is blank with 3 only wires to the fan.
    Does this mean it cannot sleep without the fan on ?
    I have read elsewhere that certain USB pins can be selected so that the whole board powers down on sleep, but I can't find anything that matches that description in the manual.

    You need to set the ACPI Standby Mode to S3 instead of S1 in BIOS Setup.

  • Macpro goes to sleep without warning and I have to reboot to get it back

    my macbook pro goes to sleep without warning on batt and I have to rebootto get it back

    Hello stephenmeyer,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    About Energy Saver sleep and idle modes in Mac OS X
    http://support.apple.com/kb/ht2412
    Intel-based Macs: Resetting the System Management Controller (SMC)
    http://support.apple.com/kb/HT3964
    Best of luck,
    Mario

  • Where we can know about the stuck threads without taking thread dump.

    Hi Everyone,
    Where we can View/know about the stuck threads without taking thread dump.
    Thank You

    Hi!
    WebLogic Server diagnoses a thread as stuck if it is continually working (not idle) for a set period of time. You can tune stuck threads in the Weblogic Server.
    You can tune a server’s thread detection behavior by changing the length of time before a thread is diagnosed as stuck, and by changing the frequency with which the server checks for stuck threads.
    It can be configured using below mentioned 2 parameters. These can be configured from Admin console -> Servers ->Configuration > Tuning tab.
    1)Stuck Thread Max Time
    2)Stuck Thread Timer Interval
    Although you can change the criteria WebLogic Server uses to determine whether a thread is stuck, you cannot change the default behavior of setting the “warning” and “critical” health states when all threads in a particular execute queue become stuck.
    There is a parameter "Stuck Thread Count" which can be configured from Console
    (Servers -> Configuration ->Overload -> Stuck Thread count) which helps to transition the Server to FAILED state once the stuck threads reaches the value.
    You can also use "OverloadProtectionMBean" for tuning. In Weblogic Server 9.x and later, it is recommended that you use the "ServerFailureTriggerMBean" in the "OverloadProtectionMBean".The ServerFailureTriggerMBean transitions the server to a FAILED state after the specified number of stuck threads are detected.The OverloadProtectionMBean has options to suspend or shutdown a failed server.
    WebLogic Server checks for stuck threads periodically. If all application threads are stuck, a server instance marks itself failed, if configured to do so, exits. You can configure Node Manager or a third-party high-availability solution to restart the server instance for automatic failure recovery.
    You can configure these actions to occur when not all threads are stuck, but the number of stuck threads have exceeded a configured threshold:
    - Shut down the Work Manager if it has stuck threads. A Work Manager that is shut down will refuse new work and reject existing work in the queue by sending a rejection message. In a cluster, clustered clients will fail over to another cluster member.
    - Shut down the application if there are stuck threads in the application. The application is shutdown by bringing it into ADMIN mode. All Work Managers belonging to the application are shut down, and behave as described above.
    - Mark the server instance as failed and shut it down it down if there are stuck threads in the server. In a cluster, clustered clients that are connected or attempting to connect will fail over to another cluster member.
    You can configure the "ServerFailureTriggerMBean" in the "OverloadProtectionMBean".
    Below is documentation link for "ServerFailureTriggerMBean" methods.
    http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e13945/weblogic/management/configuration/ServerFailureTriggerMBean.html
    You can use getStuckThreadCount() method to check the number of stuck threads and transition the server to Failed State once itreaches the limit.
    getStuckThreadCount:
    int getStuckThreadCount() - The number of stuck threads after which the server is transitioned into FAILED state. There are options inOverloadProtectionMBean to suspend and shutdown a FAILED server. By default, the server continues to run in FAILED state. If the StuckThreadCount value is set to zero then the server never transitions into FAILED server irrespective of the number of stuck threads.
    Returns:
    The StuckThreadCount value
    Default Value:
    0
    Maximum Value:
    java.lang.Integer.MAX_VALUE
    Minimum Value:
    0
    Below is documentation link for "OverloadProtectionMBean" methods.
    http://download.oracle.com/docs/cd/E11035_01/wls100/javadocs_mhome/weblogic/management/configuration/OverloadProtectionMBean.html
    In the Admin console, you can set the "FailureAction" under Servers->Configuration->Overload to force shutdown the managed server once the server is in Failed state.
    The OverloadProtectionMBean has a method getFailureAction to achieve the same.
    getFailureAction:
    String getFailureAction() - Enable automatic forceshutdown of the server on failed state. The server self-health monitoring detects fatal failures and mark the server as failed. The server can be restarted using NodeManager or a HA agent.
    Valid Values:
    OverloadProtectionMBean.NO_ACTION, OverloadProtectionMBean.FORCE_SHUTDOWN, OverloadProtectionMBean.ADMIN_STATE
    If you start the managed servers using node manager, you can enable "Auto Kill if Failed" and "Auto Restart" in the Admin console, under Servers-> configuration->Health Monitoring. Node Manager will take care of restarting the managed server if you enable "Auto Restart".
    You can also configure the "Stuck Thread Count" and "Failure Action" to "Force Immediate shutdown of the Server" from Admin console under servers-> configuration-> Overload. This will help you to shutdown the server when the stuck thread count is reached. But there is no way to release the threads once they are stuck from the configuration.
    Suppose if you set the value of the Stuck Thread Count to 20, The server will be transitioned to failed state once the count reaches 20 and if you enable the Failure Action, the server self-health monitoring detects fatal failures and mark the server as failed.
    Depending on how you are starting the servers (custom scripts or Node Manager or startup scripts,...), you can restart the servers.
    For more details on this please refer to below link:
    http://www.oracle.com/technetwork/articles/entarch/workload-management-088692.html
    Hope this helps.
    Thanks,
    Cris

  • Klaptop using /proc/acpi/sleep instead of /sys/power/state

    This is a problem in kde since it disables most of the features of klaptop. In other words for me at-least kde cpu frequency scaling, standby, suspend do not work through klaptop since it seems to use /proc/acpi/sleep instead of /sys/power/state which is the only thing available in the new kernel. I am not sure if this is a kde problem, my kernel problem, or just simply my particular problem.
    Is there a way to fix this.
    Thanks for the help,
    Matt

    It also seems kde is not reading the current cpu frequency correctly. It seems to use/proc/cpuinfo instead of /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq to get the current frequency. In addition when clicking setup helper applications under ACPI Config in klaptop I get:
    The /opt/kde/bin/klaptop_acpi_helper application does not seem to have the same size or checksum as when it was compiled we do NOT recommend you proceed with making it setuid-root without further investigation
    Are other people having these problems as well or is this unique to me.

  • Which ipaddress which user use in domain enviroment without sccm

    How to know which user which ipaddress use in dmain environment without sccm if any command available or if any free software.
    Ananda

    Hi lyncLab,
    You may take a look at this thread:
    How to find user's IP on domain network ???
    Besides, if you have PC's hosts name, then you may take use of NSlookup to find the IP address:
    Nslookup
    Best regards
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

Maybe you are looking for

  • Installing Adobe Acrobat 8.0

    I have Adobe Acrobat 5.0. My computer crashed a few days ago. Before it crashed I had updated to Adobe Acrobat 8.0 (and honestly I do not know how I updated, but I did) Anyway, the computer crashed and after fixing it it would not convert any documen

  • Trouble exporting photos in 8.1.2

    I am now unable to export photos in 8.1.2 to any desktop folder. I just noticed it. The message I am getting is: "unable to create/users/ldvf/desktop/ras" ras is the desktop folder. I have also tried exporting to other folders as well as the desktop

  • White space around graphic

    Is there any way to get rid of the white space around an image. A lasso?

  • TM-PI-ECC Integration

    Hello All, I have been trying to build an interface between TM and ECC systems [via PI]using standard interfaces. TM source standard interface is : TransportationRequestQuotationConfirmation_Out. Could anyone please help me in knowing the name of sta

  • SCCM2007 R2 tasksequence failed: "Content location request for PackageID failed. (Code 0x80040103)

    Hi All I have a lab setup with a single SCCM server configured. I am facing problem in executing a Task Sequence (this is my first TS) as and when i run it it throws below error:  A0100002 is the boot wim. <http://social.technet.microsoft.com/Forums/