I’m rolling my own simple caching solution to improve the UX of a lengthy lookup. The basic outline is that I have a class handling all accountId lookups, and another class called AccountListCache with two variables: a timestamp indicating when it was created, and a List object containing a whole bunch of accountId objects. When the lookup is invoked, that
Tag: multithreading
Thread.sleep behaviour with non-volatile boolean variable
According to the JLS 17 specification section 17.3: For example, in the following (broken) code fragment, assume that this.done is a non-volatile boolean field: The compiler is free to read the field this.done just once, and reuse the cached value in each execution of the loop. This would mean that the loop would never terminate, even if another thread changed
Java Thread Race, Code messes up after changing System.out.println
I am having issues with my program printing out only one winner and still allowing the other threads to finish the race while printing their time. When I take out the System.out.println line it messes everything up and I have no idea how and why it is possible. I am using the Runnable and lock statements and still running into
How to correctly use the Threads
I have the following task : Create Class called: ElementsProvider(int n, List elements) that will provide N random elements into given list. Elements Provider will be an thread. Try create 4 instances, each of this instance will add 1000 random elements into the list. start all instances at once and wait until they end. print list size. And here is
using the Hazelcast distributed locks with Coroutines in Kotlin and Spring webflux
My question is as the documentation says, fencedlocks are reentrant locks for “THREADS” and I am using spring boot with Kotlin and webflux so in my application I am using Coroutines for concurrency and as you probably know spring webflux provides an event-loop with a limited number of threads to fulfilling the Coroutines, what will happen if I use this
Executor service returning incorrect response
I am creating future list from a list of calls to executor service submit method based on student ID. The response from service is not returning for all studentId’s. It runs for the right number of times but the studentId getting used in service call is either first or last. It is ignoring the middle ones. Please check the code
Is Reentrant Lock a Object level lock or Class level lock?
I see in many tutorials for Reentrant lock, they create a new Reentrant lock and resource is injected, lock and unlock of reentrant lock is called in try/finally block. I don’t understand the connection between this lock and resource which is used in the thread. Below is an example of tutorial on Reentrant lock Resource code Resource being used in
Read Large file in Chunks and Compare each line in Java
I have a text file with entries like below. I want to read the file as input and compare the time consumed by each event using Java. Like event1 has taken (11025373 – 11025373) = 4ms time. (start – end) event2 has taken (11025397 – 11025387) = 10ms time. I initially thought to read line by line. Considering the input
Accessing to TextView from class implementing Runnable – Android Studio
I have a class ExampleRunnable which is calling the method under certain restrictions to change value percentage and TextView’s which will display this after setting visibility one line aboce. I am trying to display this value till i wont stop this thread. My application is freezing because i cant access to TextView. Is there any solution, to get access to
sorting files using multithreading in java
I was given an assignment to write all ordered contents of given files into a result.txt. At first, the filenames are split into different Arraylists where each file contains a label in a format #n/N where N is the total number of files. e.g. British explorer James Clark Ross led the first expedition to reach the north magnetic pole #001/004