Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of java multithreading implementation

Shulou Source: shulou.com Published: 2022-05-31 17:49:48 09月12日 Update

This article mainly introduces the relevant knowledge of "what are the methods of java multithreading". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what are the methods of java multithreading?" can help you solve the problem.

The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer.

1. Lambda expression creation thread

Instantiate the thread task class in the form of lambda, create a thread object, and pass the thread task class as a constructor parameter.

Package com.kingh.thread.create; / * create thread with lambda * * @ author > > "+ f.get () .toString (); list.add (f);} / / close thread pool pool.shutdown () / / get the running results of all concurrent tasks for (Future f: list) {/ / get the return value of the task from the Future object and output it to the console System.out.println ("> >" + f.get (). ToString ());} Date date2 = new Date () System.out.println (+ (date2.getTime ()-date1.getTime ()) + "millisecond]);} class MyCallable implements Callable {private String taskNum; MyCallable (String taskNum) {this.taskNum = taskNum;} public Object call () throws Exception {System.out.println (" > > "+ taskNum +" Task start "); Date dateTmp1 = new Date (); Thread.sleep (1000) Date dateTmp2 = new Date (); long time = dateTmp2.getTime ()-dateTmp1.getTime (); System.out.println (">" + taskNum + "Task termination"); return taskNum + "the task returns the run result, the current task time [" + time + "millisecond]";}} on "what are the methods of java multithreading", thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Threads tasks methods runs objects results interfaces knowledge programs outputs parameters multiple instances forms time industries and different practical legends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info vpn Shulou Information Linux Docker