thread-sleep

android game loop vs updating in the rendering thread

喜夏-厌秋 提交于 2019-11-29 22:25:33
I'm making an android game and am currently not getting the performance I'd like. I have a game loop in its own thread which updates an object's position. The rendering thread will traverse these objects and draw them. The current behavior is what seems like choppy/uneven movement. What I cannot explain is that before I put the update logic in its own thread, I had it in the onDrawFrame method, right before the gl calls. In that case, the animation was perfectly smooth, it only becomes choppy/uneven specifically when I try to throttle my update loop via Thread.sleep. Even when I allow the

JProgressBar not working properly

六月ゝ 毕业季﹏ 提交于 2019-11-29 18:02:02
So my JProgressBar I have set up doesn't work the way I want it. So whenever I run the program it just goes from 0 to 100 instantly. I tried using a ProgressMonitor , a Task, and tried a SwingWorker but nothing I tried works. Here is my program: int max = 10; for (int i = 0; i <= max; i++) { final int progress = (int)Math.round( 100.0 * ((double)i / (double)max) ); EventQueue.invokeLater(new Runnable() { @Override public void run() { try { Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(BandListGenerator.class.getName()).log(Level.SEVERE, null, ex); } jProgressBar2

Pausing Swing GUI

风流意气都作罢 提交于 2019-11-29 17:22:14
Hy! So I'm starting with netbeans java gui development and I have run into this problem: I have made a window with a button and a text field. When the user clicks the button I want the text field to start typing itself with a delay. So for example: textfield.text=h wait(1) sec textfield.text=he wait(1) sec textfield.text=hel wait(1) sec textfield.text=hell wait(1) sec textfield.text=hello I have already tried with Thread.sleep() , but in the example above it waits 4 seconds or so and after that displays the whole text (so it's not giving me the typo effect that I would want). Can somebody help

SystemClock.sleep() vs. Thread.sleep() while waiting for a semaphore loop

こ雲淡風輕ζ 提交于 2019-11-29 14:16:21
问题 In order to synchronize/queue access to a shared resource, I am about to use a Semaphore, aided by a wait loop. In order not to run into CPU pegging, I would like to sleep() a little bit inside that while loop. I searched the http://developer.android.com reference and found two such sleep() functions and I am confused as to which one fits which scenario: Thread.sleep() SystemClock.sleep() Which one better suits the case I described and why? 回答1: First of all, do you really need a wait loop?

Make JavaFX wait and continue with code

最后都变了- 提交于 2019-11-29 13:24:12
问题 Basically I am trying to make a short effect using JavaFX. I have the shape of a heart (added together from two circles and a polygon) that I can vary in size using the double value p . "Standart Size" would be p = 1.0; . I am trying to add a pumping effect to the heart. I have the method pumpOnce() : public void pumpOnce(){ p = p + 1; initHeart(); //Here goes what ever it takes to make stuff working!! p = p - 1; initHeart(); } initHeart() draws the heart based on p . I have found out that

Do sleep functions sleep all threads or just the one who call it?

大城市里の小女人 提交于 2019-11-29 10:22:32
I am programming with pthread on linux(Centos)? I wanna to threads sleep a short time to wait for something. I am trying to use sleep(), nanosleep(), or usleep() or maybe something can do that. I want to ask that: Do sleep functions sleep all threads or just the one who call it? Any advices or references would be appreciate. void *start_routine () { /* I just call sleep functions here */ sleep (1); /* sleep all threads or just the one who call it? what about nanosleep(), usleep(), actually I want the threads who call sleep function can sleep with micro-seconds or mili-seconds. */ ... } int

Would looping Thread.Sleep() be bad for performance when used to pause a thread?

ε祈祈猫儿з 提交于 2019-11-29 07:34:58
There is (or there has been) a lot of talk about wether it's good or bad to use the Thread.Sleep() method. From what I understand it is mainly to be used for debugging purposes. Now I wonder: is it bad to use for my specific purpose, that is, constantly looping it to be able to pause/resume the thread? I do this because I want to pause a thread that performs I/O operations and be able to resume it in a simple way. The I/O operations are basically just writing blocks of 4096 bytes to a file until all the data has been written to it. Since the file might be large and take a long time I want to

Thread sleep and precise timing [duplicate]

帅比萌擦擦* 提交于 2019-11-29 07:03:48
This question already has an answer here: How accurate is Thread.sleep? 3 answers I am making a code where I want definite precision in my timing. I use a robot to make some actions, then I use Thread.sleep(some_time) for some_time to be elapsed between the actions. But I don't get best results because as I search it, sleep is not accurate. What would be the best way to accomplish this? I mean simulate Thread.sleep with other methods. Timing in modern OSes is never precise, unless you use a language/framework that was explicitly designed for this. You can however work with a reasonable

Android Sleep/Wait/Delay function

北战南征 提交于 2019-11-29 01:31:53
first of all, I'm a beginner to android world so please apologize me if it is stupid question.. I'm trying to do following: Enable Mobile Data Wait for 10 seconds a. check if Mobile got IP address (data connected sucessfully) b. if Not connected,Disable Data c. Go to step 1 And these steps 1 to 3 are getting executed in For loop for User Given number of retries. Now my problem is: I'm stuck at step No. 2. I'm unable to make waitfor(int seconds) function. I tried using Runnable PostDelayed method but it is not giving me required output. for(retry = UserChoice; retry > 0 && !isDataAvailable ;

Simple Swing Delay

守給你的承諾、 提交于 2019-11-28 14:30:20
In a swing application, I have a popup jDialog which pops up with a jlabel that says "Hang on 5 seconds." After 5 Seconds, the label should change to "Okay, now I'm done." And a button should appear allowing the user to click continue. In the example action below (linked to a button which causes the popup), the popup appears as it should but it is blank instead of saying "Hang on 5 seconds." Then after 5 seconds everything updates and the labels are there and the button too. So what's going on? Is the thread sleeping before a repaint or something? @Action public void popUp() { popUpDialog