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
0 answers

Non-JavaFX thread communication with JavaFX thread

I am making a socket which is listening for inputs (currently just from the Terminal). When I read the input, I want to call a function in a controller class which then sends it to my application GUI. It should be an easy task, but there seems to be…
Adrian
  • 114
  • 9
0
votes
2 answers

anonymous inner class - illegal start of expression

I am writing a code for a progress bar and need to declare an anonymous inner class, but when I do, I get these: Lab2Part2.java:25: error: illegal start of expression public void actionPerformed(ActionEvent e) ^ Lab2Part2.java:25: error:…
user5382657
0
votes
1 answer

Java: Waiting connection threads created by HTTP connection are alive for very long duration

I have a server side code which checks if SOAP service is up. Code looks like: String response = ""; while (response.length() == 0) { try { final URL url = new URL("DummySoapServiceURL"); final HttpURLConnection httpConnection =…
user613114
  • 2,731
  • 11
  • 47
  • 73
0
votes
1 answer

Multithreading: Switching context

I have written a small sample code: public class Button2 implements Runnable{ JButton jButton = new JButton(); static boolean changeContext = false; public Button2(){ jButton.setText("ButtonTWO"); …
Swaraj Shekhar
  • 187
  • 1
  • 7
  • 28
0
votes
1 answer

Is @GuardedBy annotation always applicable when there is synchronized block

Is it a fair assumption to say that if a class has a synchronized block, it's always better to have @GuardedBy annotation in that class. More specifically, will there be a case where we have a synchronized block in a java file but we cannot use…
Bajji
  • 2,243
  • 2
  • 22
  • 35
0
votes
6 answers

Does this code have a race condition?

I just need to do an example of race condition with java threads, I writed this code, but I'm not sure if it has a race condition. Can someone tell me if the below code has a race condition,and also how can I improve it or make it simple? (sorry for…
Bryan Romero
  • 164
  • 2
  • 11
0
votes
2 answers

How to implement Java cron jobs with spring framework and is spring batch am i looking for?

Currently we are using java.util.concurrent.ExecutorService, java.util.concurrent.Future, java.util.concurrent.Callable to run cron jobs daily. Here our task is grabbing contacts from Gmail java api. We want to implement cron jobs with spring…
Harinath
  • 105
  • 1
  • 4
  • 12
0
votes
1 answer

Thread to process multiple rest calls

I am trying to process around 1000 files using below code: ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize); Runnable worker = null; for (File file : files) { if (file.isFile()) { worker = new…
ncp
  • 1
  • 3
0
votes
3 answers

My JLabel don't refresh quickly. Why?

I'm reading a media with vlcj and I would like to display the time elapsed and the remaining time in some JLabels. I wrote some code but it seems my JLabel.setText don't refresh more that 2 times per second. To make some more try and being sure that…
Dr_Click
  • 449
  • 4
  • 16
0
votes
2 answers

Thread.sleep doesn't force context switch apparently

Main thread creates child thread. Parent needs some work from child, but not all of it, so parent must wait until child finish that work (child will keep doing some other work). I would like to achieve it with monitors so I coded the…
JaviOverflow
  • 1,434
  • 2
  • 14
  • 31
0
votes
1 answer

Threaded NFC tag transceive calls on Android

In my application, I need to perform multiple NFC-A tag reads with NfcA.transceive() Also, the app needs to perform slow API calls associated with the different read data Therefore, I am running Callables on separate threads to handle the various…
Martin
  • 770
  • 6
  • 22
0
votes
1 answer

Export File-I/O-Operations into seperate threads recommended or maybe a must?

At the moment I'm writing tests and think about to export all File-I/O-Operations into separate threads within my GUI-App, because I fear that a large file can block the main-thread. This wouldn't be user-friendly. Its common to export…
0
votes
0 answers

Android Images are not getting downloaded (very slow)

Actually here I am trying to download the multiple images from server, when I try to download images from localhost it wotks fine (within 3 sec images getting downloaded). But when I try to download it from actual server it is taking so long…
0
votes
0 answers

Application is getting crashed when using handler and thread to download an image

//This is my My MainActivity code. public class MainActivity extends ActionBarActivity { ImageView mImageView=null,mImageView1=null; ProgressDialog progressDialog=null; ProgressDialog progressDialog1=null; Handler…
0
votes
1 answer

Is my service thread safe?

I have a singleton class MyService, it has two functions to read & write data from/to file: public class MyService { private static MyService instance; private MyFileAccessor fileAccessor; private MyService() { fileAccessor = new…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354