sleep

Java: Thread.currentThread().sleep(x) vs. Thread.sleep(x)

雨燕双飞 提交于 2019-11-27 17:34:08
I have this in my code Thread.currentThread().sleep(x); Eclipse tells me to use the static Thread.sleep(x); instead, why? What's the difference, is there some difference in functionality at all between these 2 methods? There is only one method, not two, and it is static. While you can call a static method via an instance reference, it's not good style. It indicates the programmer thinks he or she is calling an instance method. A confused programmer might be thinking he or she can cause another thread (not the current one) to sleep this way, when that's not what it does. Both your lines of code

Bash: Sleep until a specific time/date

丶灬走出姿态 提交于 2019-11-27 17:19:38
I want my bash script to sleep until a specific time. So, I want a command like "sleep" which takes no interval but an end time and sleeps until then. The "at"-daemon is not a solution, as I need to block a running script until a certain date/time. Is there such a command? SpoonMeiser As mentioned by Outlaw Programmer, I think the solution is just to sleep for the correct number of seconds. To do this in bash, do the following: current_epoch=$(date +%s) target_epoch=$(date -d '01/01/2010 12:00' +%s) sleep_seconds=$(( $target_epoch - $current_epoch )) sleep $sleep_seconds To add precision down

Sleep Command in T-SQL?

荒凉一梦 提交于 2019-11-27 16:46:07
Is there to way write a T-SQL command to just make it sleep for a period of time? I am writing a web service asynchronously and I want to be able to run some tests to see if the asynchronous pattern is really going to make it more scalable. In order to "mock" an external service that is slow, I want to be able to call a SQL server with a script that runs slowly, but isn't actually processing a ton of stuff. look at the WAITFOR command Eg. -- wait for 1 minute WAITFOR DELAY '00:01' -- wait for 1 second WAITFOR DELAY '00:00:01' This command allows you a high degree of precision but is only

Pause an Android App with Phonegap

…衆ロ難τιáo~ 提交于 2019-11-27 16:30:35
问题 Is there any way to programmatically pause an Android app in Phonegap? I would like to mimic the behavior that occurs when you hit the HOME button. I've already had to overwrite the back button handler using this, and while in most cases I want it to do my action, when in a particular state the user would expect the app to minimize, and I want to replicate this behavior. Keep in mind, on Android this is not the same as closing the app. That is quite easy to do with device.exitApp(); but I

Can I prevent phone from sleep on a webpage

限于喜欢 提交于 2019-11-27 16:02:21
In app I can use http://developer.android.com/reference/android/os/PowerManager.WakeLock.html but is there a way to keep webpage running and prevent from going to sleep? It would be nice if it runs at least on android. In an app there are a couple of ways you can do it, but I guess you mean just in a mobile web page, viewed in any browser via Android. With normal HTML/Javascript/etc., I really, really doubt it. It actually may be possible using Flash (on flash-enabled phones with plugins enabled), though, at least in specific circumstances. I say this because, in a test app without the WAKE

Android sleep() without blocking UI

99封情书 提交于 2019-11-27 14:40:48
问题 For my new Android application I need a function, that timeout my application for 3 Seconds. I tried the function "sleep()" like this: seekBar1.setProgress(50); // Set something for my SeekBar try{ Thread.sleep(3000); // Wait for 3 Seconds } catch (Exception e){ System.out.println("Error: "+e); // Catch the exception } button.setEnabled(true); // Enable my button It seems to work, but if I was running the application it does it like this: Wait for 3 Seconds, set progress and enable button. I

How do you make a program sleep in C++ on Win 32?

非 Y 不嫁゛ 提交于 2019-11-27 14:39:49
问题 How does one "pause" a program in C++ on Win 32, and what libraries must be included? 回答1: #include <windows.h> Sleep(number of milliseconds); Or if you want to pause your program while waiting for another program, use WaitForSingleObject. 回答2: If you are using boost, you can use the thread::sleep function: #include <boost/thread/thread.hpp> boost::system_time time = boost::get_system_time(); time += boost::posix_time::seconds(1); boost::thread::sleep(time); Otherwise, you are going to have

Interrupting or stopping a sleeping thread [duplicate]

瘦欲@ 提交于 2019-11-27 14:20:46
This question already has an answer here: How can I kill a thread? without using stop(); 3 answers How to stop or interrupt a sleeping thread in java.? I have a thread that syncs data and sleeps for 10 minutes in run() method, if i want to stop the sync by stopping the thread when it is sleeping.? How can this be achieved? Call the interrupt() method on your thread. This will cause the sleep to be cancelled and an InterruptedException will be thrown. You can interrupt a sleeping thread with Thread.interrupt() . Now stopping a thread is deprecated - what if the thread is holding a lock to

Precise thread sleep needed. Max 1ms error

这一生的挚爱 提交于 2019-11-27 13:46:22
I have thread that runs loop. I need that loop to be run once every 5ms (1ms error). I know that Sleep() function is not precise. Do you have any suggestions? Update. I can't do it other way. At the end of loop I need some kind of Sleep. I don't want to have 100% CPU loaded either. From the question tags I suppose you are on windows. Take a look at Multimedia Timers , they advertise precision under 1ms. Another options is to use Spin Locks but this will basically keep a cpu core at maximum usage. Arno Don't use spinning here. The requested resolution and accuracy can be reached with standard

C# put pc to sleep or hibernate

邮差的信 提交于 2019-11-27 12:11:02
问题 I want to put my system to either sleep or hibernate, two different options. How would I do this with API's, I don't really want to use Process, and that doesn't allow me to choose what method I want for this action. 回答1: // Hibernate Application.SetSuspendState(PowerState.Hibernate, true, true); // Standby Application.SetSuspendState(PowerState.Suspend, true, true); Or, if you like system calls: [DllImport("Powrprof.dll", CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool