Questions tagged [java-threads]

For questions related to Java threads, including concurrent data structures, the fork-join framework, atomic classes, thread locking/synchronization, visibility and latency

Examples include:

  • Usages of java.util.concurrent.* data structures
  • Fork-join framework,
  • Atomic classes
  • Thread locking/synchronization, visibility and latency
1037 questions
0
votes
1 answer

Unable to understand the value change of a variable pizzaNum

In this code below I am trying to make 10 pizzaz (as the value of pizzaNum becomes 10) and then serve them form different threads (I just used one thread for question), but just in the start of run method the value of pizzaNum becomes 0. Why? I am…
affanBajwa
  • 158
  • 3
  • 13
0
votes
3 answers

Interaction with user on Thread cause my app crash

My app crashes if TextView.setText is inside Thread: NOTE: The following class is inside of MainActivity. private class StreamThread extends Thread { public StreamThread() { } public void run() { byte[] buffer = new…
user4400167
0
votes
2 answers

How can I programmatically cause a delay in Android?

I tried to use Thread.sleep() but it didn't work. When I use it, the app stops responding. I need to put some delays in my code like this: public void inicioJogo(){ for (int jogada = 1; jogada <= 50; jogada++) { for (int contador…
0
votes
1 answer

What exactly does the call to the SwingUtilities.invokeLater() method into the main class that perform a Swing application?

I am pretty new in Swing and I have the following doubt about this main class that start a Swing application founded on an tutorial project: package com.caveofprogramming.designpatterns.demo1; import javax.swing.SwingUtilities; import…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
0
votes
1 answer

Scenario's where a Java thread running in infinite loop for a long run be terminated by JVM

I have a Runnable thread which loops through an infinite loop. Per iteration it sleeps upto next task time and then does some task. This task is very critical hence makes the thread running it also very critical. I am not really a java thread expert…
Xavier DSouza
  • 2,861
  • 7
  • 29
  • 40
0
votes
0 answers

getting all running threads in JVM

I am willing to run another jar file and get its threads, so I thought running the jar this way will run the jar on the current JVM: Process p = Runtime.getRuntime().exec("java -jar " + path); And then to get the threads like this: ThreadGroup…
Tarek
  • 1,904
  • 2
  • 18
  • 36
0
votes
3 answers

Android - View.post() does not modify TextView from onCreate()

Why does this not change my TextView's text ? I have a TextView who's text I try to modify from a view.post method. What am I doing wrong here ? mTextView = (TextView)findViewById(R.id.text_view); new Thread(new Runnable() { @Override …
user1841702
  • 2,683
  • 6
  • 35
  • 53
0
votes
3 answers

Can I call a synchronized method that calls a non-synchronized method that calls a synchronized method?

In Java using the synchronized keyword all within a single object and thread. Can I call a synchronized method that calls a non-synchronized method that calls a synchronized method, without the final synchronized method blocking for the first…
willjgriff
  • 783
  • 2
  • 6
  • 11
0
votes
1 answer

Reading to Process Freezes Console

So, I've been working on a Java app that's supposed to let people run their Minecraft servers using a program with an interface. When you run a shell script, all output is put in the window, and then you can write input. The input is then read by…
ColonelHedgehog
  • 438
  • 3
  • 18
0
votes
1 answer

synchronized access is slow

I share a list between many thread. All the data needed by the thread are there before they start, I don't add any other value to the list. Each tread take a value in list, value is removed from the list and there is a distant call done. This block…
robert trudel
  • 5,283
  • 17
  • 72
  • 124
0
votes
3 answers

Serialized access to Collection with the use of ConcurrentLinkedQueue

I have the following question concerning Java 7 ConcurrentLinkedQueue. Let us assume that I have the following class: public class Blah { private ConcurrentLinkedQueue queue; public Blah() { queue = new…
nick.katsip
  • 868
  • 3
  • 12
  • 32
0
votes
1 answer

Using TimerTask to change shader causes error 50% of the time - LIBGDX

I'm changing my shader using a TimerTask: public java.util.Timer ExplodeTimerTask = new Timer(); ExplodeTimerTask.schedule(new TimerTask() { @Override public void run(){ …
gogonapel
  • 788
  • 6
  • 17
0
votes
1 answer

Handling Exception in java Piped Streams

I have a xmlStream which I am converting to jsonStream using org.apache.wink.json4j.utils.XML. Here is the code public void process(InputStream xmlStream) { final BufferedInputStream bufferedXmlStream = new BufferedInputStream(xmlStream); …
user1739372
  • 193
  • 1
  • 5
0
votes
1 answer

Refresh TexView while Loop using UI Thread

I want refresh a TextView every 1 Second , I tried some Code s but doesent work . this is a loop , which put value in text . public void buttonOnClick(View v) throws InterruptedException { Button button=(Button) v; String t; …
0
votes
1 answer

What will happen use run() instead of start() of a thread?

Fallowing thread class is working fine. I can understand its process. Then I changed mc.srart() into mc.run() but nothing changed and there was no any errors. Can someone please explain this to me ? can we always use run() instead of start()…
DSM
  • 31
  • 1
  • 8