Home > Java > javaTutorial > What is the difference between asynchronous and synchronous in java

What is the difference between asynchronous and synchronous in java

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-05-10 21:01:12
forward
1027 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 Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template