thread-sleep

Java full screen background color wont change?

百般思念 提交于 2019-12-02 09:07:56
问题 I have some code that creates a full screen icon in java and sets the background color to pink and the foreground color to red. However every time i run it, it never changes the background color to red but just keeps it see through. I put the code below. The main java: import java.awt.*; import javax.swing.*; @SuppressWarnings({ "serial" }) public class bob extends JFrame{ public static void main(String[] args) { DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);

Java full screen background color wont change?

跟風遠走 提交于 2019-12-02 04:08:30
I have some code that creates a full screen icon in java and sets the background color to pink and the foreground color to red. However every time i run it, it never changes the background color to red but just keeps it see through. I put the code below. The main java: import java.awt.*; import javax.swing.*; @SuppressWarnings({ "serial" }) public class bob extends JFrame{ public static void main(String[] args) { DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN); bob b = new bob(); b.run(dm); } public void run(DisplayMode dm){ setBackground(Color.PINK);

Android: C++ thread not waking up if screen-locked or in background. Works fine when app is in use

风流意气都作罢 提交于 2019-12-01 19:40:10
In our Android app, we have UI component and core C++11 module. A thread is running based on std::chrono::system_clock::time_point , such as below: while(this->m_ConditionVariable.wait_until(lock, this->m_Object.to_time_point()) == std::cv_status::no_timeout) { // ... handle any notify() or arbitrary sleep breaks } Execute(); // <--- not being called consistently Now, we are testing with 1 minute time_point . If the app is in use, then the Execute() is invoked as expected. However, if the app is moved to background or if even the screen is locked, then the Execute() -s behavior is not

Android: C++ thread not waking up if screen-locked or in background. Works fine when app is in use

China☆狼群 提交于 2019-12-01 19:35:55
问题 In our Android app, we have UI component and core C++11 module. A thread is running based on std::chrono::system_clock::time_point , such as below: while(this->m_ConditionVariable.wait_until(lock, this->m_Object.to_time_point()) == std::cv_status::no_timeout) { // ... handle any notify() or arbitrary sleep breaks } Execute(); // <--- not being called consistently Now, we are testing with 1 minute time_point . If the app is in use, then the Execute() is invoked as expected. However, if the app

Thread.sleep waits more than expected

梦想的初衷 提交于 2019-12-01 14:43:56
问题 The following code: long msBefore = System.currentTimeMillis(); //Thread.currentThread().setPriority(Thread.MAX_PRIORITY); try {Thread.sleep(200); } catch (InterruptedException e){} System.out.println("Time: " + (System.currentTimeMillis() - msBefore)); prints : Time: 578 Time: 594 Time: 625 Time: 640 Time: 641 Time: 609 Time: 625 Time: 625 Time: 610 Time: 609 Time: 625 Time: 625 Time: 422 Time: 625 Time: 594 Time: 609 Time: 625 Time: 594 Time: 594 Time: 625 Where's the problem?? 回答1: I have

make PHP wait until a function completes?

喜你入骨 提交于 2019-12-01 06:06:28
Is there any way to make PHP wait until a function returns before continuing? This is my code: <?php set_time_limit(0); function waitforchange($nof) { $lfilemod=filemtime($nof); while(filemtime($nof) == $lfilemod) { clearstatcache(); usleep(10000); } } waitforchange('./blahblah.txt') sleep(5); echo 'done'; ?> It is supposed to wait until blahblah.txt changes, wait another five seconds after that, then print out "done", however, it prints out "done" after five seconds, regardless whether the file actually changed. PHP is single-threaded, which means that it executes one instruction at a time

make PHP wait until a function completes?

最后都变了- 提交于 2019-12-01 03:15:42
问题 Is there any way to make PHP wait until a function returns before continuing? This is my code: <?php set_time_limit(0); function waitforchange($nof) { $lfilemod=filemtime($nof); while(filemtime($nof) == $lfilemod) { clearstatcache(); usleep(10000); } } waitforchange('./blahblah.txt') sleep(5); echo 'done'; ?> It is supposed to wait until blahblah.txt changes, wait another five seconds after that, then print out "done", however, it prints out "done" after five seconds, regardless whether the

Making a Thread to Sleep for 30 minutes

江枫思渺然 提交于 2019-12-01 03:04:26
I want to make my thread to wait for 30 minutes. Are there any problems of doing this? You can make your thread sleep for 30 minutes like this: Thread.sleep(30 * // minutes to sleep 60 * // seconds to a minute 1000); // milliseconds to a second Using Thread.sleep is not inherently bad. Simply explained, it just tells the thread scheduler to preempt the thread. Thread.sleep is bad when it is incorrectly used. Sleeping without releasing (shared) resources : If your thread is sleeping with an open database connection from a shared connection pool, or a large number of referenced objects in memory

Sleep function in android program

落花浮王杯 提交于 2019-11-30 17:43:13
Having some problem getting my program to sleep What im trying to do is when the btnStart is pressed firs randomly set pictures to 12 ImageButtons Then i want it to pause for 5 secs and then change the first ImageButton to another picture My code looks like this, right now it pauses straight away when the button is pressed... btnStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Collections.shuffle(pic); int time=1; press=true; pic.get(0).setImageDrawable(getResources().getDrawable(R.drawable.memgreen)); pic.get(1)

Thread.sleep() VS Executor.scheduleWithFixedDelay()

不想你离开。 提交于 2019-11-30 13:40:11
问题 Goal: Execute certain code every once in a while. Question: In terms of performance, is there a significant difference between: while(true) { execute(); Thread.sleep(10 * 1000); } and executor.scheduleWithFixedDelay(runnableWithoutSleep, 0, 10, TimeUnit.SECONDS); ? Of course, the latter option is more kosher. Yet, I would like to know whether I should embark on an adventure called "Spend a few days refactoring legacy code to say goodbye to Thread.sleep()". Update: This code runs in super/mega