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
Tag: multithreading
Spring Data Redis JedisConnectionException: Unexpected end of stream
Redis 3.0.5 Spring Data Redis 1.3.6 jedis 2.6.3 – Our is web application which receives data from redis over pub/sub. – Also performs read/write of data on redis as key/value pairs. – read/write happens on listener thread, independent monitoring thread and http request threads. – We have used a same connection factory for Listener and redis template – Our redis
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 – Multi-threaded crawler with ExecutorService
I’m working to make a crawler in Java. I made a single-threaded crawler to visit a single page and fetch all links on that page. Now I want to make it multi-threaded but facing difficulties. In the very beginning I start with single link of the page and crawl through all the links in it and Now I want to
Does a synchronized block trigger a full memory fence for arrays?
I am confused about sharing arrays safely between threads in Java, specifically memory fences and the keyword synchronized. This Q&A is helpful, but does not answer all of my questions: Java arrays: synchronized + Atomic*, or synchronized suffices? What follows is sample code to demonstrate the issue. Assume there is a pool of worker threads that populates the SharedTable via
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