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

In case of independent task, which is better way to use a child thread or use message queue

I have a use case where I am iterating over a list and for each element I am doing a task. I can not do this synchronously because the code is part of a Kafka consumer and the run time can not be large. listElem.size() - 50k sample code for(int i :…
Kakarot
  • 195
  • 2
  • 10
-1
votes
1 answer

set is not applicable to arguments (int,int)

Hi I am doing a concurrent programming task in java where I'm using an executorService consisting of 10 threads. I have an array containing 100 elements all set initially to 1000. What I am trying to do is I have 2 indexes from the array, and I need…
-1
votes
1 answer

How to run Timer independently in Java?

I am trying to build multiple Timers and scheduled independent tasks for each of them. I have a constructor for holding a Timer and its variable. Then, I will call them one by one but I found that the variables, passed to the Timer constructor, are…
WILLIAM
  • 457
  • 5
  • 28
-1
votes
1 answer

When to use BlockingQueue over TransferQueue?

Difference between BlockingQueue and TransferQueue have well explained the difference between these two queues, but looks like TransferQueue is just a better version of BlockingQueue. Is there any situation that we should use BlockingQueue over…
Deqing
  • 14,098
  • 15
  • 84
  • 131
-1
votes
1 answer

Running a compiler in parallel with java.utils.concurrent

I am making a compiler for a language in Java and I want it to compile many files in parallel. I have my class Compiler.java that has the constructor Compiler(String fileName) and the method compile() So to compile a single file in my main all I do…
-1
votes
1 answer

This is my first program. I wanted to create a converts currencies and gives advices to user on how best to spend money. I need some advances

package firstproject; import java.util.Scanner; public class Currency{ public static void main(String[] args) { int rubles = 100; double rateUSD = 1.35; double rateEUR = 1.20; double rateGBP = 1.02; …
-1
votes
1 answer

Concurrency feature of JavaCallable-Future using AWS-SQS

Current-approach: For Spring Boot app, in AWS environment: The service-layer spawns 5 threads, using ExecutorService --> Callable-Future for concurrent processing. On completion, each callable-future task, returns a response. The 5 responses, from…
-1
votes
2 answers

ExecutorService interface execute method using Executors class in java

Please don't close this question. It is not related to question What does it mean to "program to an interface"? I am trying to learn ExecutorService interface and its methods. I created an object of type ExecutorService using Executors class static…
-1
votes
1 answer

java.util.ConcurrentModificationException on replacing string in kotlin

I'm getting concurrent exception replacing string inside iterator. fun replaceValuesInURLString(allFieldsValues: HashMap, urlString: String): String { var result = urlString val iteratorValues =…
Ragini
  • 765
  • 1
  • 11
  • 29
-1
votes
1 answer

a concurrency problem makes volitile not work

B thread reads two global variables, A thread writes two global variables. How could second much bigger than first? public class ThreadTest { private static volatile int first = 0; private static volatile int second = 0; private static…
Karl.Li
  • 169
  • 12
-1
votes
2 answers

AtomicLong in Multithreading

I'm trying to use AtomicLong in Multi Threading Environment. My desired result is not working, public class Account implements Runnable { private final AtomicLong amount = new AtomicLong(0); public Account(long difference) { …
parrotjack
  • 432
  • 1
  • 6
  • 18
-1
votes
1 answer

Which one of these two concurrent implementations is a better faster

I've two implementations of generating prime numbers in parallel. The core code is taken from another post here in Stackoverflow. I'd like to know which one of these implementations is preferred and why? Also if there are better and faster solutions…
Prana
  • 693
  • 1
  • 7
  • 16
-1
votes
1 answer

Avoiding usage of two AtomicInteger in a loop Java

I wish to read/write an array (and update another one) with a parallelStream, without an index. AtomicInteger doesn't allow bitwise operations, and using j.get() * 2 is slow: final int[] j = {0}; ps.parallelStream().forEach(p -> { long k =…
Harry Cotte
  • 90
  • 2
  • 14
-1
votes
1 answer

What is the advantage of using functional style in java?

Do i have any advantage while using functional style in my below example case I have a below method public static String someMethod(String source) { //some operation return source; } I changed above method to below style. public static…
-1
votes
1 answer

Best way to block other threads until one is finished

I have many threads which monitor a certain state. If the application gets into that state, then I need to do some extra work. I want to allow just 1 thread to execute that and want to block the others until that work is finished. Blocking mean,…
HamoriZ
  • 2,370
  • 18
  • 38