refactor: removed client side threads from a server, improved test log files rotation;

This commit is contained in:
Oleg Agafonov 2023-11-27 18:13:05 +04:00
parent 0470ae9799
commit c5632f6868
6 changed files with 75 additions and 62 deletions

View file

@ -1,8 +1,8 @@
package mage.utils;
import org.apache.log4j.Logger;
import java.util.concurrent.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* Util method to work with threads.
@ -11,57 +11,6 @@ import java.util.concurrent.*;
*/
public final class ThreadUtils {
private static final Logger logger = Logger.getLogger(ThreadUtils.class);
public static final ThreadPoolExecutor threadPoolSounds;
public static final ThreadPoolExecutor threadPoolPopups;
private static int threadCount;
static {
threadPoolSounds = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
threadCount++;
Thread thread = new Thread(runnable, "SOUND-" + threadCount);
thread.setDaemon(true);
return thread;
}
}) {
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
t = findRealException(r, t);
if (t != null) {
// TODO: show sound errors in client logs?
//logger.error("Catch unhandled error in SOUND thread: " + t.getMessage(), t);
}
}
};
threadPoolSounds.prestartAllCoreThreads();
threadPoolPopups = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
threadCount++;
Thread thread = new Thread(runnable, "POPUP-" + threadCount);
thread.setDaemon(true);
return thread;
}
}) {
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
// catch errors in popup threads (example: card popup over cards or chat/log messages)
t = findRealException(r, t);
if (t != null) {
logger.error("Catch unhandled error in POPUP thread: " + t.getMessage(), t);
}
}
};
threadPoolPopups.prestartAllCoreThreads();
}
public static void sleep(int millis) {
try {
Thread.sleep(millis);
@ -81,9 +30,6 @@ public final class ThreadUtils {
/**
* Find real exception object after thread task completed. Can be used in afterExecute
*
* @param r
* @param t
* @return
*/
public static Throwable findRealException(Runnable r, Throwable t) {
// executer.submit - return exception in result