thread-sleep

Sleep function in android program

本秂侑毒 提交于 2019-12-09 00:28:55
问题 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;

reading a log file and displaying it in jTextArea [closed]

回眸只為那壹抹淺笑 提交于 2019-12-08 12:33:19
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I am trying to read a file that changes dynamically and display its contents in jTextArea. I am using buffered reader for reading. I have tried to display the contents on console and it works fine, but doesn't work with jTextArea. I am doing something like while(true) { line = br.readLine(); if

Pause a BackgroundWorker for n-seconds

陌路散爱 提交于 2019-12-08 10:42:44
问题 I was feeling nostalgic and have developed a text based Adventure Game Creator IDE, which has a Windows Form that displays messages to a rich text box. I have written a message dispatcher class that will send text (room descriptions and messages) from a stream to the text box using a BackgroundWorker. This works brilliantly, but I am having a small problem... I need to do is be able to pause/hold the Background worker for any number of seconds of my choosing. The reason for this is that, in

Handler postDelayed and Thread.sleep()

独自空忆成欢 提交于 2019-12-07 04:20:44
问题 I have a thread.sleep and a handler postDelayed in my code: handler.postDelayed(new Runnable() { @Override public void run() { Log.e(TAG, "I ran"); mIsDisconnect = false; } }, DISCONNECT_DELAY); After the handler code and after the user press the button I have this: while (mIsDisconnect) { try { Thread.sleep(DELAY); } catch (InterruptedException e) { Log.e(TAG, "problem sleeping"); } } If the user wait long enough I can get the "I ran" in my log. But if the user press the button before the

Thread and battery consumption

流过昼夜 提交于 2019-12-07 01:29:07
问题 I am working on app that check some of the status of phone every 5 seconds. I done it that: Thread checking = new Thread() { public void run(){ while( <<some status>> ) { <<checkstatus and do something>> Thread.sleep(5000); } } } This is bad for the battery? How can I do it in the other way? Service stop working after couple seconds. 回答1: To answer your question, it depends what you are doing inside the while loop. If you are not using and waking up any "expensive" components (such as

Changing images in a Loop - Android

和自甴很熟 提交于 2019-12-06 08:08:52
问题 I'm wondering why still I couldn't to figure out a way to do this. Although it seems like very simple, I spent my entire day for this. But couldn't do that. I have set of dice images. 1.png,2.png,.... and 6.png. There is an ImageView in my layout. That is, ImageView dice = (ImageView) findViewById(R.id.imageViewrollingdiceOne); Here I want to change this imageView rapidly to see a some kind of a visual/animation using above 6 images. For that I wrote following piece of code. Code 1: for (int

How to sleep in the Linux kernel space?

♀尐吖头ヾ 提交于 2019-12-06 02:55:49
问题 I have a kernel thread which is assigned on a specific CPU with FIFO and highest priority. This thread sleeps from time to time but the time interval must be as precise as possible. So with this in mind what would be the most precise way to sleep in the kernel space? 回答1: Here is a related excerpt from Documentation/timers/timers-howto.txt: NON-ATOMIC CONTEXT: You should use the *sleep[_range] family of functions. There are a few more options here, while any of them may work correctly, using

Is it Really Busy Waiting If I Thread.Sleep()?

偶尔善良 提交于 2019-12-05 15:17:21
问题 My question is a bit nit-picky on definitions: Can the code below be described as "busy waiting"? Despite the fact that it uses Thread.Sleep() to allow for context switching? while (true) { if (work_is_ready){ doWork(); } Thread.Sleep(A_FEW_MILLISECONDS); } PS - The current definition for busy waiting in Wikipedia suggests that it is a "less wasteful" form of busy waiting. 回答1: Any polling loop, regardless of the time between polling operations, is a busy wait. Granted, sleeping a few

How to sleep in the Linux kernel space?

放肆的年华 提交于 2019-12-05 10:55:40
I have a kernel thread which is assigned on a specific CPU with FIFO and highest priority. This thread sleeps from time to time but the time interval must be as precise as possible. So with this in mind what would be the most precise way to sleep in the kernel space? Here is a related excerpt from Documentation/timers/timers-howto.txt : NON-ATOMIC CONTEXT: You should use the *sleep[_range] family of functions. There are a few more options here, while any of them may work correctly, using the "right" sleep function will help the scheduler, power management, and just make your driver better :)

Handler postDelayed and Thread.sleep()

怎甘沉沦 提交于 2019-12-05 09:40:45
I have a thread.sleep and a handler postDelayed in my code: handler.postDelayed(new Runnable() { @Override public void run() { Log.e(TAG, "I ran"); mIsDisconnect = false; } }, DISCONNECT_DELAY); After the handler code and after the user press the button I have this: while (mIsDisconnect) { try { Thread.sleep(DELAY); } catch (InterruptedException e) { Log.e(TAG, "problem sleeping"); } } If the user wait long enough I can get the "I ran" in my log. But if the user press the button before the delay is up, it seems that the postDelayed never gets a chance to execute. My question is, does the