All Questions

1645
votes
39answers
557001 views

"implements Runnable" vs. "extends Thread"

From what time I've spent with threads in Java, I've found these two ways to write threads: With implements Runnable: public class MyRunnable implements Runnable { public void run() { //...
157
votes
15answers
128726 views

What's the difference between Thread start() and Runnable run()

Say we have these two Runnables: class R1 implements Runnable { public void run() { … } … } class R2 implements Runnable { public void run() { … } … } Then what's the diffe...
368
votes
10answers
203186 views

The difference between the Runnable and Callable interfaces in Java

What is the difference between using the Runnable and Callable interfaces when designing a concurrent thread in Java, why would you choose one over the other?
142
votes
13answers
73169 views

Naming threads and thread-pools of ExecutorService

Let's say I have an application that utilizes the Executor framework as such Executors.newSingleThreadExecutor().submit(new Runnable(){ @Override public void run(){ // do stuff } ...
27
votes
3answers
24315 views

removeCallbacks not stopping runnable

I am calling from a method: myHandler.postDelayed(mMyRunnableHide, 6000); which calls: public Runnable mMyRunnableHide = new Runnable() { public void run() { mTextDisplay.setText(...
29
votes
4answers
51745 views

Android update TextView in Thread and Runnable

I want to make a simple timer in Android that updates a TextView every second. It simply counts seconds like in Minesweeper. The problem is when i ignore the tvTime.setText(...) (make it //tvTime.set...
23
votes
4answers
60657 views

Android: How do I stop Runnable?

I tried this way: private Runnable changeColor = new Runnable() { private boolean killMe=false; public void run() { //some work if(!killMe) color_changer.postDelayed(changeColor, ...
126
votes
6answers
117967 views

Runnable with a parameter?

I have a need for a "Runnable that accepts a parameter" although I know that such runnable doesn't really exist. This may point to fundamental flaw in the design of my app and/or a mental block in my...
5
votes
1answers
6176 views

FacesContext.getCurrentInstance() returns null in Runnable class

I am trying to get the FacesContext by calling FacesContext.getCurrentInstance() in the run() method of a Runnable class, but it returns null. public class Task implements Runnable { @Override ...
29
votes
7answers
29221 views

Should you synchronize the run method? Why or why not?

I have always thought that synchronizing the run method in a java class which implements Runnable is redundant. I am trying to figure out why people do this: public class ThreadedClass implements Run...

Previous Next