mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-21 01:00:54 +08:00
Improve async code example. Don't generate JSO aliases for static
methods
This commit is contained in:
parent
9e5309a986
commit
891ec3e6fd
@ -29,6 +29,7 @@ import org.teavm.model.AnnotationValue;
|
||||
import org.teavm.model.CallLocation;
|
||||
import org.teavm.model.ClassReader;
|
||||
import org.teavm.model.ClassReaderSource;
|
||||
import org.teavm.model.ElementModifier;
|
||||
import org.teavm.model.FieldReader;
|
||||
import org.teavm.model.FieldReference;
|
||||
import org.teavm.model.MethodDescriptor;
|
||||
@ -145,6 +146,9 @@ class JSDependencyListener extends AbstractDependencyListener {
|
||||
if (addInterface(exposedCls, iface)) {
|
||||
added = true;
|
||||
for (MethodReader method : iface.getMethods()) {
|
||||
if (method.hasModifier(ElementModifier.STATIC)) {
|
||||
continue;
|
||||
}
|
||||
if (!exposedCls.inheritedMethods.containsKey(method.getDescriptor())) {
|
||||
String name = method.getName();
|
||||
AnnotationReader methodAnnot = method.getAnnotations().get(JSMethod.class.getName());
|
||||
|
@ -36,30 +36,21 @@ public final class AsyncProgram {
|
||||
|
||||
report("");
|
||||
final Object lock = new Object();
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
}, "Test Thread").start();
|
||||
|
||||
}, "Test Thread");
|
||||
t.start();
|
||||
|
||||
Thread t2 = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
}, "Test Thread 2");
|
||||
t2.start();
|
||||
}, "Test Thread 2").start();
|
||||
|
||||
report("Should be main");
|
||||
report("Now trying wait...");
|
||||
|
@ -33,7 +33,7 @@
|
||||
</head>
|
||||
<body onload="runAll()">
|
||||
<div id="description">This application shows how TeaVM can handle multiple threads and synchronization primitives
|
||||
(see <a href="https://github.com/konsoletyper/teavm/tree/master/teavm-samples/teavm-samples-async">source code on GitHub</a>).</div>
|
||||
(see <a href="https://github.com/konsoletyper/teavm/tree/master/samples/async">source code on GitHub</a>).</div>
|
||||
|
||||
<div id="blocks">
|
||||
<div class="block" id="stdout-wrapper">
|
||||
@ -59,30 +59,21 @@ public final class AsyncProgram {
|
||||
|
||||
report("");
|
||||
final Object lock = new Object();
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
}, "Test Thread").start();
|
||||
|
||||
}, "Test Thread");
|
||||
t.start();
|
||||
|
||||
Thread t2 = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
doRun(lock);
|
||||
} catch (InterruptedException ex) {
|
||||
report("Exception caught: " + ex.getMessage());
|
||||
}
|
||||
}, "Test Thread 2");
|
||||
t2.start();
|
||||
}, "Test Thread 2").start();
|
||||
|
||||
report("Should be main");
|
||||
report("Now trying wait...");
|
||||
@ -99,18 +90,18 @@ public final class AsyncProgram {
|
||||
boolean[] prime = new boolean[1000];
|
||||
prime[2] = true;
|
||||
prime[3] = true;
|
||||
nextPrime: for (int i = 5; i < prime.length; i += 2) {
|
||||
int maxPrime = (int)Math.sqrt(i);
|
||||
for (int j = 3; j <= maxPrime; j += 2) {
|
||||
nextPrime: for (int i = 5; i < prime.length; i += 2) {
|
||||
int maxPrime = (int) Math.sqrt(i);
|
||||
for (int j = 3; j <= maxPrime; j += 2) {
|
||||
Thread.yield();
|
||||
if (prime[j] && i % j == 0) {
|
||||
if (prime[j] && i % j == 0) {
|
||||
continue nextPrime;
|
||||
}
|
||||
}
|
||||
prime[i] = true;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
if (prime[i]) {
|
||||
sb.append(i).append(' ');
|
||||
}
|
||||
@ -144,9 +135,9 @@ public final class AsyncProgram {
|
||||
|
||||
private static void withoutAsync() {
|
||||
report("Start sync");
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int j = 0; j <= i; ++j) {
|
||||
for (int j = 0; j <= i; ++j) {
|
||||
sb.append(j);
|
||||
sb.append(' ');
|
||||
}
|
||||
@ -157,9 +148,9 @@ public final class AsyncProgram {
|
||||
|
||||
private static void withAsync() throws InterruptedException {
|
||||
report("Start async");
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int j = 0; j <= i; ++j) {
|
||||
for (int j = 0; j <= i; ++j) {
|
||||
sb.append(j);
|
||||
sb.append(' ');
|
||||
}
|
||||
@ -187,6 +178,7 @@ public final class AsyncProgram {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
</pre>
|
||||
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user