Questions tagged [java.util.concurrent]

Java package which contains utility classes commonly useful in concurrent programming. This package includes a few small standardized extensible frameworks, as well as some classes that provide useful functionality and are otherwise tedious or difficult to implement.

java.util.concurrent is a core Java package which contains utility classes commonly useful in concurrent programming. This package includes a few small standardized extensible frameworks, as well as some classes that provide useful functionality and are otherwise tedious or difficult to implement.

Main components include:

  • Executors
  • Queues
  • Timing
  • Synchronizers, Semaphores, CountDownLatch
  • Concurrent Collections

More information is available at the JavaDoc description

1396 questions
-2
votes
1 answer

Why does not the size of ArrayBlockingQueue object update?

I'm following an example at Chapter 23.6 Proceducer/Consumer Relationship: ArrayBlockingQueue ("Java - How to Program 10th). I tried to run example but I don't understand why "buffer.size()" is not updated at the beginning. I did a little…
Hikaru
  • 23
  • 1
  • 4
-2
votes
1 answer

Why is CountDownLatch source so complicated?

I want to know why utils.concurrent have such complicated source code. This is some code I came up for the CountDownLatch and after testing it I was expecting to find something similar in the source code, but no, it is super complex. Is there wrong…
AFP_555
  • 2,392
  • 4
  • 25
  • 45
-2
votes
1 answer

Acquire method of Semaphore blocked thread with priority?

Semaphore sema = new Semaphore(1); Create a Semaphore object and the default initialization, the only one license, when multiple threads at the same time trying to get the license, must change is only one thread can access permission, then other…
wanghao
  • 271
  • 1
  • 7
  • 21
-2
votes
5 answers

Need to execute a piece of code repeatedly for fixed duration in java

I have written a piece of code . How can I get that code to run for certain duration repeatedly, say for 10 second?
Ranjan Kumar
  • 107
  • 1
  • 10
-2
votes
3 answers

Adding elements to a list with multiple threads: how to make it thread-safe?

I am using multiple threads via an ExecutorService to add objects to a list with several for-loops. As the normal ArrayList is not thread-safe, I am using a CopyOnWriteList. However, adding the elements as in the code example below does not give me…
madison54
  • 743
  • 2
  • 8
  • 19
-2
votes
1 answer

ConcurrentHashMap memory allocation

ConcurrentHashMap chm= new ConcurrentHashMap(8,1,16); Now according to the above configuration the ConcurrentHashMap will divide the table into 16 segments. Now each segment is a individual hasmap. Let's take the entry object size as x bytes. Then…
Maclean Pinto
  • 1,075
  • 2
  • 17
  • 39
-2
votes
2 answers

ThreadPool quitting upon submit

As soon as I submit a Runnable to the ThreadExecutor, it quits and I can't figure out why. I've traced the code, but to no avail. Does anyone have any idea why this would be? By quits, i mean the task is submitted and it never runs the Multiplier…
HelloWorld
  • 605
  • 1
  • 7
  • 22
-2
votes
1 answer

Regarding countdown latch implementation

I have been going through the program which starts three threads and print their corresponding value such that T3 is executed first, then the T1 thread, and lastly the T2 thread is executed. Below is the program. I just want to know if you guys…
user2094103
  • 685
  • 3
  • 7
  • 14
-3
votes
2 answers

concurrentHashMap.merge(key,1,Integer::sum) : Is this operation threadsafe?

concurrentHashMap.merge(key,1,Integer::sum) Is the above operation thread-safe? What is the best way to make it threadsafe?
-3
votes
1 answer

Java Concurrent API's Lock not working as intended

I am trying to synchronize 2 threads using Java Concurrent's lock API. The code basically increments a counter to a certain number using 2 threads but the result i am getting is less than the said number even after using locks. Code- import…
wut
  • 19
  • 4
-3
votes
1 answer

Java map cache for highly multiple threads

Please suggest which map can be used for caching. My use case is a highly multi threaded server that I would like to synchronise put map but get map is not synchronised. My expectation is: if put happens, then an immediate get should have the…
erdarun
  • 441
  • 1
  • 8
  • 14
-4
votes
2 answers

Fill the dynamic data with each row columns by column Using iText in Java

Hi Every One I've a pdf report generated with iText containing a PdfPTable added to MultiColumnText, sometimes becomes so large that it will be split on more than one page, Here am added sample Code, Its working as Page…
kks
  • 342
  • 5
  • 25
-4
votes
2 answers

ConcurrentModificationException with for loop

I am getting a ConcurrentModificationException with my for loop and I do not know how to solve this problem. This is my code: for(Map.Entry entry:oldPresentationMap.entrySet()) { …
-4
votes
2 answers

Execute pairwise threads concurrently

class A { public void func() { new Thread() { public void run() { // statements } } .start(); new Thread() { public void run() …
-5
votes
1 answer

How to block current thread until user calls a specific method?

I need to block the current thread until I call one of two following methods (which I created). onJobComplete() onJobError(Throwable t) These methods will be called from a different thread. Is this possible with a CountDownLatch(1)? (which I would…
ZakTaccardi
  • 12,212
  • 15
  • 59
  • 107
1 2 3
93
94