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
0
votes
1 answer

Service.restart() generates an huge unwanted amount of threads

When the user types in a TextField: I need to search some data via WebRequest and display them. When the user types in more than one character, the previous download should be cancelled and a new one should start. So I use a Task to download data…
user2468425
  • 419
  • 2
  • 13
0
votes
2 answers

Enforce executorService.awaitTermination while using CompletionService

I am trying to submit multiple tasks and obtain the results as and when it is available. However, after the end of the loop, I have to enforce that all the tasks complete within specified amount of time. If not, throw an error. Initially, all I had…
dmachop
  • 824
  • 1
  • 21
  • 39
0
votes
1 answer

ThreadPoolExecutor Vs ExecutorService for service time out use cases

I am going to implement Timeout framework between two services. I am looking at pros & cons of ThreadPoolExecutor VS ExecutorService Code with ExecutorService. ExecutorService service = Executors.newFixedThreadPool(10); for ( int…
0
votes
1 answer

Concurrent write to a file in multithreading

I am new to concurrent programming and have read synchronization and Locks. What i get to know that we can write one at a time. However my requirement is to: 1. write concurrently for different key values 2. lock only at key level i.e. if one…
Aquarius24
  • 1,806
  • 6
  • 33
  • 61
0
votes
1 answer

Synchronize 2 methods

public class ActionForm { private Account temporaryAccount = null; private Document document; /** * Save document from another thread that do not have a SecurityContext */ public void saveByAccount(Account…
0
votes
1 answer

On what object Reentrant lock aquire lock on?

Hello I have question about ReentrantLocks in Concurrent package. //First Object ob = new Object(); synchronized(ob){ } //Second Lock lock = new ReentrantLock(); lock.lock(); try{ } finally{ lock.unlock(); } It says both Pieces of code are…
0
votes
2 answers

Task Execution With Special Requirements In Java

Having to sink in my teeth into Java Executor Service I noticed that it falls flat for some of my requirements: I need to implement a small reactive system. So a Task can result in a new Task. The tasks schedule dynamically either as a reaction of…
Martin Kersten
  • 5,127
  • 8
  • 46
  • 77
0
votes
2 answers

Java: notifyObservers not concurrent?

I have 4 observers listening on an observable data. However one of my observer is slower and could take. I just saw the code of notifyObserver as:- 132 public void notifyObservers(Object arg) { 133 /* 134 * a…
0
votes
2 answers

ConcurrentLinkedQueue: NotSerializableException

I need to serialize ConcurrentLinkedQueue. public class Service implements Serializable { private static Queue messages = new ConcurrentLinkedQueue<>(); public class Serialize { public static Queue getMessages()…
0
votes
4 answers

Is there a Java Lock implementation with timeouts

I have a spring application which can run in a clustered environment. In that environment I use Redis (and Redisson) as a distributed lock-service. Many of the locks are used to e.g. protect certain tasks which can only run once at a time, or which…
0
votes
0 answers

Determining the optimum number of worker threads

Imagine, that we have X (30 for example) number of system. Each system has an array of Entities on which it has to operate (the number of Entities for a system is different for each) . So basically, systems contain algorithms and Entities contain…
0
votes
1 answer

How to know only n number of threads running per second using RateLimiter

I am doing a simple demo implementation to understand RateLimiter. I did a simple class, it showing multiple threads running in a second. If you check in output, 2nd Second, it showing thread-6 also started without completion of thread-2 and…
Kumar
  • 33
  • 1
  • 9
0
votes
2 answers

Waiting for a hierarchy of tasks to complete

This is an abstraction of my actual problem, but I hope it's accurate enough to explain things. I'm processing a file hierarchy, and I'm processing the files asynchronously using a Java ThreadPoolExecutor with a finite number of threads and an…
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0
votes
0 answers

How to log runnable within RejectedExecutionHandler

I wanna to log failed runnables. For that I consider: public class LoggableRejectedExecutorHanlder implements RejectedExecutionHandler { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { .... log.error("…
Bogdan
  • 702
  • 3
  • 6
  • 22
0
votes
1 answer

Executor framework abnormal behaviour

Hi I am using Executors for loading some data in parallel. My application is fetching some data from DB which have parent-child relation like: parent 1 -> [child11, child12,..., child1N] parent 2 -> [child21, childy22,..., child2N] ..... parent N ->…