Skip to content
Advertisement

Tag: multithreading

Is replacing one java object reference with another considered thread safe, or are there potential synchronicity issues I’m overlooking?

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

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

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

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

Advertisement