Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of java multithreading implementation

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report