mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
Executor improvement
This commit is contained in:
1 parent
8832d67d8b
commit
97422300c8
7 files changed
+31
-16
No files matched your search
@@ -106,7 +106,7 @@ public class CompilationBox extends JFrame {
|
||||
null, Arrays.asList(new JavaSourceFromString("Compiled", source))).call();
|
||||
String res = out.toString();
|
||||
if (res.isEmpty()) {
|
||||
SingleThreadedExecutor.execute(() -> {
|
||||
SingleThreadedExecutor.submit(() -> {
|
||||
try {
|
||||
File clazz = new File(tmpFolder, "Compiled.class");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package me.ByteEdit.boxes;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class GlobalSearchOpenBox extends JFrame {
|
||||
JList<Info> list = new JList(model);
|
||||
list.addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
SingleThreadedExecutor.execute(() -> {
|
||||
SingleThreadedExecutor.submit(() -> {
|
||||
Info val = list.getSelectedValue();
|
||||
if (val != null && !val.owner.equals(Main.currentNodeName)) {
|
||||
Main.selectFile(val.nodePath);
|
||||
|
||||
@@ -211,7 +211,7 @@ public class RenameBox extends JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
SingleThreadedExecutor.execute(() -> {
|
||||
SingleThreadedExecutor.submit(() -> {
|
||||
// refresh
|
||||
Main.decompileCurrentNode();
|
||||
name = newName;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TypeOpenBox extends JFrame {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
String val = list.getSelectedValue();
|
||||
if (val != null && !val.equals(Main.currentNodeName)) {
|
||||
SingleThreadedExecutor.execute(() -> Main.selectFile(val));
|
||||
SingleThreadedExecutor.submit(() -> Main.selectFile(val));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,15 +4,29 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class SingleThreadedExecutor {
|
||||
|
||||
// We don't need to run every Runnable,
|
||||
// we only care about the last submitted Runnable.
|
||||
private static final Object lock = new Object();
|
||||
private static Runnable runnable;
|
||||
private static final LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
|
||||
|
||||
private static final Thread thread = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
queue.take().run();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
while (true) {
|
||||
Runnable r = null;
|
||||
synchronized (lock) {
|
||||
while (runnable == null)
|
||||
lock.wait();
|
||||
r = runnable;
|
||||
runnable = null;
|
||||
}
|
||||
try {
|
||||
r.run();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}, "SingleThreadedExecutor");
|
||||
|
||||
@@ -21,7 +35,10 @@ public class SingleThreadedExecutor {
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public static void execute(Runnable r) {
|
||||
queue.add(r);
|
||||
public static void submit(Runnable r) {
|
||||
synchronized (lock) {
|
||||
runnable = r;
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -513,7 +513,7 @@ public class Main extends JFrame {
|
||||
});
|
||||
scrollPane.setViewportView(tree);
|
||||
tree.addTreeSelectionListener(e -> SingleThreadedExecutor
|
||||
.execute(() -> selectFile(((ByteEditTreeNode) e.getPath().getLastPathComponent()).path)));
|
||||
.submit(() -> selectFile(((ByteEditTreeNode) e.getPath().getLastPathComponent()).path)));
|
||||
new DropTarget(tree, new DropTargetListener() {
|
||||
|
||||
@Override
|
||||
@@ -606,7 +606,7 @@ public class Main extends JFrame {
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == 116 && currentNodeName != null) { // F5
|
||||
SingleThreadedExecutor.execute(Main::decompileCurrentNode);
|
||||
SingleThreadedExecutor.submit(Main::decompileCurrentNode);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -661,7 +661,7 @@ public class Main extends JFrame {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
EnumDecompiler selected = (EnumDecompiler) e.getItem();
|
||||
SingleThreadedExecutor.execute(() -> {
|
||||
SingleThreadedExecutor.submit(() -> {
|
||||
decompiler = selected;
|
||||
if (currentNodeName != null) {
|
||||
decompileCurrentNode();
|
||||
|
||||
Reference in new issue
Block a user