In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the process of multithreaded execution". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the process of multithreaded execution.
1. The main thread waits for the child thread to complete its execution before executing-- Thread.join ()
Vector vector = new Vector (10); for (int I = 0; I < 10; iTunes +) {MyThread myThread = new MyThread ("id" + I, "name" + I, roles); Thread t = new Thread (myThread); vector.add (t); t.start () } for (Thread thread: vector) {try {thread.join ();} catch (InterruptedException e) {e.printStackTrace ();}}
2. Java multithreading-- let the main thread wait for the child thread to finish execution (CountDownLatch class)
Runable interface implementation class
Import com.winning.jcfw.core.util.SpringUtil;import com.winning.jcfw.empi.dao.DaGrJbxxDao;import com.winning.jcfw.empi.entity.PatientEntity;import com.winning.jcfw.empi.service.RegisterEmpiService;import com.winning.jcfw.empi.service.impl.RegisterEmpiSerImpl;import lombok.extern.slf4j.Slf4j;import org.apache.commons.lang.StringUtils;import java.util.List;import java.util.concurrent.CountDownLatch / * * @ ClassName DaGrJbxxEmpiRunnable * @ Description Public Security Table DA_GR_JBXX thread executes single generation EMPI * @ Author WJX * @ Date 17:45 * * / @ Slf4jpublic class DaGrJbxxEmpiRunnable implements Runnable {private RegisterEmpiService registerEmpiService = SpringUtil.getBean (RegisterEmpiSerImpl.class); private DaGrJbxxDao daGrJbxxDao = SpringUtil.getBean (DaGrJbxxDao.class); private CountDownLatch dLatch; / * Mechanism Code Collection * / private List jgList Public DaGrJbxxEmpiRunnable (List threadJgLsit,CountDownLatch downLatch) {super (); jgList = threadJgLsit; dLatch = downLatch;} @ Override public void run () {for (int ionometer I 0) {s = null; for (Node t = tail; t! = null & & t! = node T = t.prev) if (t.waitStatus {System.out.println ("blocking Thread 1"); LockSupport.park (); System.out.println ("Thread 1 finished");}); t.start () Try {Thread.sleep (2000); System.out.println ("Wake up Thread 1"); LockSupport.unpark (t); Thread.sleep (5000); System.out.println ("main thread ends") } catch (InterruptedException e) {e.printStackTrace ();}}
Blocking thread 1
Wake thread 1
Thread 1 finished execution.
The main thread ends
Thank you for your reading, the above is the content of "the process of multithreaded execution". After the study of this article, I believe you have a deeper understanding of the process of multithreaded execution, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.