Home> Java> javaTutorial> body text

What is the difference between asynchronous and synchronous in java

WBOY
Release: 2023-05-10 21:01:12
forward
906 people have browsed it

Difference

1. The difference between asynchronous and synchronous is generally whether the caller needs to wait for the result.

2. Do you need to wait for the result to be synchronized?

3. You can also decide whether you need to wait for the result to be asynchronous.

Example

--异步 Thread t3 = new Thread(new Runnable() { @Override public void run() { try { for (int i = 0; i < 10; i++) { Thread.sleep(1100); System.out.println("4:" + i); } } catch (Exception e) { e.printStackTrace(); } } });t3.start(); --同步 SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { // TODO Auto-generated method stub } }); t3.isAlive()
Copy after login

The above is the detailed content of What is the difference between asynchronous and synchronous in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!