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

Concurrent execution of remove and get in java ConcurrentHashMap

I was reading the implementation of Java11 Concurrent Hashmap. Below is the snipped of get: public V get(Object key) { Node[] tab; Node e, p; int n, eh; K ek; int h = spread(key.hashCode()); if ((tab = table) !=…
-2
votes
2 answers

Iterating over a list of user defined class using Iterator class of enhanced for loop gives java.util.ConcurrentModificationException

Iterating over a list of user defined class using Iterator class of enhanced for loop gives java.util.ConcurrentModificationException exception but when using the traditional for loop it runs just fine. Actually I am trying to implement my own…
-2
votes
1 answer

Why does this code get stuck in infinite loop

public void bad() { final ConcurrentMap chm = new ConcurrentHashMap<>(); final String key = "1"; chm.computeIfAbsent(key, __ -> { chm.remove(key); return 1; }); } Of…
-2
votes
1 answer

How to Measure execution time for a multi threaded task in java

I have a method which makes lets say 100k http calls to an API, for that reason I am making the http calls concurrently to avoid http bottleneck. But I would also like to time the whole method without blocking any threads. ExecutorService…
SomeOnionGamer
  • 203
  • 1
  • 4
  • 8
-2
votes
1 answer

Does this construction make sense?

Faced a project with this code: public class IndexUpdater implements Runnable { @Override public void run() { final AtomicInteger count = new AtomicInteger(0); FindIterable iterable =…
-2
votes
1 answer

CompletableFuture simplified custom example

Could someone explain the original source of CompletableFuture in simple ways? Particularly what happens in timedGet(long nanos)? This is source code link…
J J
  • 51
  • 1
  • 5
-2
votes
1 answer

Can CountDownLatch be implemented using an exclusive lock?

The source code of JDK1.8 is implemented by AQS shared lock.What are the considerations for using shared locks? Why not use exclusive locks? Attached below is the code implemented by my exclusive lock: public class MyCountDownLatch { private static…
wsat
  • 3
  • 2
-2
votes
1 answer

Concurrent modification exception in JAVA client to client through server

I'm trying to implement client to client chat which goes through the server. But it is giving me Concurrent execution exception. Any advice will be very appreciated. The source code I've managed to write: Below is my Server Program: public class…
-2
votes
2 answers

Can the `ConcurrentHashMap::get` method return a "dirty" valuekkkjjjjj?

While writing the value via put method if another thread tries to read the value for the same key, what will the reader thread get? The old value, the new value or some "junk" value?
-2
votes
1 answer

How to improve performance for search keywords highlighting on file using pdfclown

I am using pdfclown and below code is taking around 100 seconds to highlighting search keywords in same file.Kindly provide your inputs for improving performance in below code.Please find the jar path in below url to run this…
Seshadri
  • 101
  • 1
  • 1
  • 9
-2
votes
1 answer

Java synchronized locking Class, not Object?

Recently I have read Bruce Eckel (Thinking in Java), and I have found some problem: block synchronized(Object) locking Class! not Object of this Class. This code proves mentioned above : public class Main { public static void main(String[]…
-2
votes
2 answers

ConcurrentHashMap read, write and clear()

Suppose there are 3 reading threads and 1 writing thread. The writing thread calls map.clear(). What exception or effect will be caused by it?
Pradeep
  • 12,309
  • 3
  • 20
  • 25
-2
votes
1 answer

When thread syncronization happens in java?

Am new to Java Thread , while reading i could see that same instances on thread object should wait until the current thread get finished execution . Consider I have two Objects , one is WebApp class WebApp{ private String webappName; …
Ansar Samad
  • 729
  • 2
  • 8
  • 15
-2
votes
2 answers

How to increment AtomicInteger twice?

I need to increment AtomicInteger twice, like: ++i; ++i; By the endless ciycle, i want to increment counter twice and check it on the parity. But i'm always getting the variable which was incremented once. How to fix it?
-2
votes
1 answer

ThreadPoolExecutor not assigning tasks to worker threads

My ThreadPoolExecutor is not assigning tasks to worker threads. As I don't know how this problem is arising so will explain current situation. CorePoolSize = 15, Max PoolSize = 100, KeepAliveTime 5 minutes, ArrayBlockingQueue of size…