I want to create a custom log4j2 rolling file appender. I need to create this custom appender because I want to wrap the file name with current thread name. We are trying to migrate log4j 1.x to recent log4j2 version and previously we had used DailyRollingFileAppender to log all activities of our application. please find the below code. Here we
Tag: multithreading
Can another thread see an effectively immutable object in an inconsistent state if it is published with a volatile reference?
According to Java Concurrency in Action if we have the following class: and we initialise an instance of this class and publish it in a non-safe way (through a simple public field for example), then the assertCorrectness() might indeed throw an AssertionError, if called from another thread. In other words, this means that some another thread might see an up-to-date
Java ParallelStream: several map or single map
Introduction I’m currently developing a program in which I use Java.util.Collection.parallelStream(), and wondering if it’s possible to make it more Multi-threaded. Several small map I was wondering if using multiple map might allow the Java.util.Collection.parallelStream() to distribute the tasks better: Single big map For example a better distribution than: Question Is there one of the solutions that is more suitable
Graceful shutdown of multithreaded java server using executor service
I refactored a single-threaded server to be capable of multithreading and accepting multiple clients at the same time. To do so, I spawn a new ClientHandler thread for each new client and submit it to an ExecutorService. I want to initiate a server shutdown by entering a new line to System.In. However, I am not able to shut down the
Share an array between threads in java
I’m currently working on my own little boardgame and came across a problem with multithreading. I have one thread that renders the board and one that supplies the data to render. The supply thread writes his data to one array and then the renderer takes this data and renders it on the screen (The render thread never writes something to
Async with single thread in Android
I read some stack overflow answers about sync, async, and threading on post A and post B. The main point I got from the post is “multithreading is only one kind of asynchrony. Threading is about workers; asynchrony is about tasks” from post A and “Technically, the concept of synchronous/asynchronous really does not have anything to do with threads” from
Getting IllegalMonitorStateException while printing arraylist using threads
I am trying to print out the content of arraylist using 2 threads, my main goal is to make threads read arraylist in a synchronized way and print its content. Eventhough I use synchronized block, I still am getting IllegalMonitorStateException. I know this is a basic question but I can not get it working, pardon me. And here is myThread
Cannot load a thread that loads chart from JFreeChart until clicked
I think I did everything right. All I want is to load the thread that contains chart after the main thread that loads the components and window is finished. But it didn’t work. Somehow I have to click jPanel1 (the panel that will load the chart) and the chart is loaded. Any help would be appreciated. What I’ve tried: Changing
How to control child-thread lifecycle and synchonize it with main-thread?
I am trying to create another thread that processes data while main thread doing some more. Main thread must wait till another thread finishes doStuff with all elements. And my implementation is pretty straight forward. Please, take a look at processData and tell me is there some more Java-like way to do it? I read about Phaser but still can’t
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 is : What I want to do is for a list of files