runnable

ScheduledThreadPoolExecutor only “ticking” once

老子叫甜甜 提交于 2019-12-24 05:13:05
问题 I was using a CountDownTimer for some countdown functionality I have in my Activity . I decided to move away from CountDownTimer and use ScheduledThreadPoolExecutor because CountDownTimer s can't cancel themselves in onTick() . For some reason, my Runnable in the following code only executes once. I'm not sure why it isn't executing multiple times. The destroyCountdownTimer() function is not getting hit. private ScheduledThreadPoolExecutor mCountdownTimer; private Tick mTick; class Tick

Java starting two threads? [duplicate]

本秂侑毒 提交于 2019-12-24 04:48:06
问题 This question already has answers here : What is the difference between Thread.start() and Thread.run()? (9 answers) Closed 4 years ago . i am new to java. I have two classes that looks like: public class hsClient implements Runnable { public void run() { while(true){ } } } public class hsServer implements Runnable { public void run() { while(true){ } } } If i try to start both classes as Thread it wont start the second thread. It looks like he stuck in the first one. This is my main class:

Run a runnable JAR file in a folder / Directory with a UTF-8 style name

╄→尐↘猪︶ㄣ 提交于 2019-12-24 00:39:01
问题 When I create a jar file in ordinary way like this: C:/myFolder/program.jar It could be run without any problem, but when I create abnormal name (UTF-8 languages) for folder like this: C:/پوشه/program.jar program cannot run and OS (Windows for me) says this: Title: Java Virtual Machine Launcher Context: Error: Unable to access jarFile C:/پوشه/program.jar Is it possible to solve this problem? 回答1: This problem could be solved by this solution: Error: Unable to access jarfile. Encoding issue

My JProgressBar is not Updating Until it is 100%

余生长醉 提交于 2019-12-23 12:53:47
问题 Ok, I have the following code. public class MyProgressBar extends JPanel implements MyData, Serializable { /** * */ public static final int MAX = 10000; public static final int WIDTH = 400; public static final int HEIGHT = 75; private JProgressBar MyBar = new JProgressBar( SwingConstants.HORIZONTAL, 0, MAX ); private JFrame MyFrame = new JFrame(); private int MyValue = 0; private Thread MyThread = new Thread( new ProgressThread() ); public MyProgressBar() { add(MyBar); int x = ( MyData.SCREEN

how does thread.interrupt() sets the flag?

南笙酒味 提交于 2019-12-23 06:07:53
问题 From the docs: The Interrupt Status Flag The interrupt mechanism is implemented using an internal flag known as the interrupt status. Invoking Thread.interrupt sets this flag. When a thread checks for an interrupt by invoking the static method Thread.interrupted, interrupt status is cleared. The non-static isInterrupted method, which is used by one thread to query the interrupt status of another, does not change the interrupt status flag. By convention, any method that exits by throwing an

Cancel the Runnable in the .runOnFirstFix() method of LocationOverlay Object

风流意气都作罢 提交于 2019-12-23 03:04:19
问题 I have an application the leans heavily on map functionality. From the first Activity I call the runOnFirstFix() method to load a lot of data from a database once the location of the user has been found, but I also want to be able to interrupt this runnable and stop it mid execution for when I switch activity or the user presses the button to stop it running. myLocationOverlay.runOnFirstFix(new Runnable() { public void run() { mc.animateTo(myLocationOverlay.getMyLocation()); mc.setZoom(15);

Android Chronometer own implementation

吃可爱长大的小学妹 提交于 2019-12-22 18:15:37
问题 I've developed an own implementation of a Chronometer. I did the follow: Create a Service (CronoService), that use a Runnable object that execute the thread. The Runnable will loop each 0.1 secs. Messenger Object that will receive messages from Ui to Start, Pause or Resume the Chronometer. Intent that will broadcast the time after each loop of the Runnable object. The code is: public class CronoService extends Service { public static final int PARAR = 0; public static final int EMPEZAR = 1;

Handler/Runnable delays producing events that are out of sync sometimes

ぃ、小莉子 提交于 2019-12-22 10:27:22
问题 When trying to learn how to create a delay I researched and found the dominant answer to be to use Handler/Runnable/postDelayed. Handler handler=new Handler(); final Runnable r = new Runnable() { public void run() { delayedMethod(); } }; handler.postDelayed(r, 1000); That worked ok for a while, but I've added a few more things going on and now they are sometimes happening in the wrong order. This set of events: paintScreen1() ... delayedPaintScreen2() ... paintScreen3() is screwing up

Why is posting & cancelled a runnable on a View and Handler result in different bahviour?

有些话、适合烂在心里 提交于 2019-12-22 05:25:34
问题 I've been playing about with Runnable s and have discovered that if you postDelayed a Runnable on a View then removing the callback won't work, however if you do the same but post the Runnable on a Handler then removing the callback does work. Why does this work ( Runnable run() code never gets executed): Runnable runnable = new Runnable() { @Override public void run() { // execute some code } }; Handler handler = new Handler(); handler.postDelayed(runnable, 10000); handler.removeCallbacks

Check if Android handler has callbacks

Deadly 提交于 2019-12-22 04:53:08
问题 I have some code which sets a timer, but if a user sets the timer while it is in use I need to remove the runnable which runs the timer and start it again. But when no handler callback runnable exists and this code is called it crashes my application. So I need to check if a handler is running, if so then end it and restart it, but looking through the documentation and other Stackoverflow questions, I cannot see if this is possible. Here is my code, I have commented around the code which