Java Eclipse Error, March 6th, 2023

I got the following error in Eclipse IDE while launching:

error occurred during initialization of boot layer

I removed the Debug Configuration (under Run -> Debug Configurations, then under Java, I used the Red X icon at top to remove the Debug Configuration)

Then I created a New Debug Configuration under Java

And it appears to be running correctly

Free Java Code Splice for writing logs to a unique txt file

		String filename = "storyOutlinesReceived-"+System.nanoTime()+".txt";
		try {
			FileHandler fileHandler = new FileHandler("c:\\storyGenOutput\\"+filename, true);
			logger.addHandler(fileHandler);
		} catch (IOException e) {
			logger.severe("Exception enabling log file to be written to disk");
		}

Requires

import java.util.logging.FileHandler;
import java.util.logging.Logger;

// Example setup
private static Logger logger = Logger.getLogger(StoryProcessingServer.class.toString());

Requires code added to module-info.java, for example

module StoryoutlineProcessingServer {
	requires java.logging; // Requires this line
	requires java.desktop;
	requires FileUtilityLibrary;
}

Working on a Simple Multithreaded Producer model that generates Story Outlines and sends them to a Simple Multithread Consumer over a TCP Socket that writes them to Disk

Capitalizes on the following class I am providing freely

package multithreading;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

public class ThreadUtil {
	private static Logger logger = Logger.getLogger(ThreadUtil.class.toString());
	private static BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(6);
	private static ThreadPoolExecutor threadPoolExecutor;
	
	
	public static BlockingQueue<Runnable> getWorkQueue() {
		if (null == workQueue) {
			workQueue = new ArrayBlockingQueue<>(6);
		}
		return workQueue;
	}
	
	public static ThreadPoolExecutor getThreadPool() {
		if (null == threadPoolExecutor) {
			threadPoolExecutor = new ThreadPoolExecutor(6, 12, 1000, TimeUnit.MILLISECONDS, getWorkQueue());
		}
		
		return threadPoolExecutor;
	}
	
	public static void addTask(Runnable task) {
		getThreadPool().submit(task);
	}
}

Simply create a Runnable using a lambda method or by implementing the interface

Wrap it in a thread

and add the task

example code, the code on this page is Provided as is an should not be deemed immediately production ready

Thread consumer = new Thread(getConsumer());
				
ThreadUtil.addTask(consumer);
ThreadUtil.addTask(consumer);
ThreadUtil.addTask(consumer);
ThreadUtil.addTask(consumer);
	
public static Runnable getConsumer() {
   return () -> {
         System.out.println("Add meaningful code in place of this");
   }:
}

Thread Pool seemed to have some bugs when I was working with it, wise to test with different processor sets. 6 used in above code (new ArrayBlockingQueue<>(6) and ThreadPoolExecutor(6, 12, 1000, TimeUnit.MILLISECONDS….) is particular to the processor I am working on currently.

Published by techinfodebug

Flex and Java Developer, Christian, Art, Music, Video, and Vlogging

Leave a comment