How to realize asynchronous information processing with JAVA

Usually, synchronization means that a certain process of a task will use serialization processing for multiple threads, while asynchrony means that a certain process can allow multiple threads to process at the same time. Asynchronous usually represents better performance, because it relies heavily on buffering, which is a typical practice of using space for time. For example, in computers, cache acts as a buffer between cpu and disk io to coordinate the high-speed computing ability of cpu and the low-speed reading and writing ability of disk.

(1): Restarting a java program starts a process

You can start runtime. getruntime (). exec ("Java-classpath. xxx") with the operating system command line;

(2): can you add a special processing function to the addtolist function in the module that receives the message? When the function is executed, first add the message to the list, then detect whether there is a processing thread at present, and if not, start the thread.

(3): If you want to save some work, you can use BlockingQueue instead of list, so that thread waiting and waking up can be realized without writing code. If you have to use list, then do a good job of synchronizing

list:

Java codeclass message consumer extends the ad {private list <: YourMessageType> list; private boolean running = true; public MessageConsumer(List< YourMessageType> list) {this.list = list; } public void run() { while (running) { YourMessageType msg = null; try { synchronized(list) { while (list.size() == ) { list.wait(); } msg = list.remove(); list.notiryAll(); } } catch (Exception e) { e.printStackTrace(); } if (msg == null) continue; //System.out.println(msg); //printmessage}}//Call the sample classshare module {list <; YourMessageType> list = new ArrayList< YourMessageType> (); ...}public class Main { public static void main(String[] args) { ShareMudule sm; //so on ... Thread t = new MessageConsumer(sm.list); t.start(); ... }}