Skip to content
Advertisement

Tag: multithreading

How to iterate on concurrentLinkedQueue by multiple threads?

In my application data producing speed (which is stored in in concurrentLinkedQueue) is greater than i can consume with single thread. I have decided to start with creating 4 threads to consume the data, to prevent my application from “out of memory exception”. Questions : Any other better design for the above problem with an example ? Can we iterate

Will using a parallel stream on a single-core processor be slower than using a sequential stream?

I am applying an operation to every element in a very large LinkedList<LinkedList<Double>>: On my computer (quad-core), parallel streams seem to be faster than using sequential streams: However, not every computer is going to be multi-core. My question is, will using parallel streams on a single-processor computer be noticeably slower than using sequential streams? Answer This is highly implementation specific,

How to run 2 methods concurrently in same class with Java

I would like to use 2 methods in the same class concurrently using the same object in Java. For example: And using this methods in another method: note: They don’t have to be synchronized. Answer There are several ways to achieve your task. You have quiet easy situation when threads should not be synchronized. You can use ExecutorService from Java

Mutex Locks vs Peterson’s Algorithm?

Do mutex locks ensure bounded waiting condition ? Is it possible if two threads are trying to get hold of a lock, but only one process (just by luck) gets it again and again. Since Peterson’s Algorithm ensures bounded waiting, is it better to use that instead of mutex locks ? Answer It is possible to have unbounded wait with

Android – Prevent white screen at startup

As we all know, many Android apps display a white screen very briefly before their first Activity comes into focus. This problem is observed in the following cases: Android apps that extend the global Application class and perform major initializations therein. The Application object is always created before the first Activity (a fact that can be observed in the debugger),

Difference between CompletableFuture, Future and RxJava’s Observable

I would like to know the difference between CompletableFuture,Future and Observable RxJava. What I know is all are asynchronous but Future.get() blocks the thread CompletableFuture gives the callback methods RxJava Observable — similar to CompletableFuture with other benefits(not sure) For example: if client needs to make multiple service calls and when we use Futures (Java) Future.get() will be executed sequentially…would

Java Chat Multi-Client Receiving thread

In a lot of multclient java programs people use a separate thread which only receives the messages from the server. Is it really necessary? Why can’t it be done in the main thread? What should be the problem? For me a separate thread to receive the messages from the server is not that necessary, it could be done simply be

Advertisement