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
+28
-13
No files matched your search
@@ -106,7 +106,7 @@ public class CompilationBox extends JFrame {
|
|||||||
null, Arrays.asList(new JavaSourceFromString("Compiled", source))).call();
|
null, Arrays.asList(new JavaSourceFromString("Compiled", source))).call();
|
||||||
String res = out.toString();
|
String res = out.toString();
|
||||||
if (res.isEmpty()) {
|
if (res.isEmpty()) {
|
||||||
SingleThreadedExecutor.execute(() -> {
|
SingleThreadedExecutor.submit(() -> {
|
||||||
try {
|
try {
|
||||||
File clazz = new File(tmpFolder, "Compiled.class");
|
File clazz = new File(tmpFolder, "Compiled.class");
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package me.ByteEdit.boxes;
|
package me.ByteEdit.boxes;
|
||||||
|
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class GlobalSearchOpenBox extends JFrame {
|
|||||||
JList<Info> list = new JList(model);
|
JList<Info> list = new JList(model);
|
||||||
list.addListSelectionListener(new ListSelectionListener() {
|
list.addListSelectionListener(new ListSelectionListener() {
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
SingleThreadedExecutor.execute(() -> {
|
SingleThreadedExecutor.submit(() -> {
|
||||||
Info val = list.getSelectedValue();
|
Info val = list.getSelectedValue();
|
||||||
if (val != null && !val.owner.equals(Main.currentNodeName)) {
|
if (val != null && !val.owner.equals(Main.currentNodeName)) {
|
||||||
Main.selectFile(val.nodePath);
|
Main.selectFile(val.nodePath);
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ public class RenameBox extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleThreadedExecutor.execute(() -> {
|
SingleThreadedExecutor.submit(() -> {
|
||||||
// refresh
|
// refresh
|
||||||
Main.decompileCurrentNode();
|
Main.decompileCurrentNode();
|
||||||
name = newName;
|
name = newName;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class TypeOpenBox extends JFrame {
|
|||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
String val = list.getSelectedValue();
|
String val = list.getSelectedValue();
|
||||||
if (val != null && !val.equals(Main.currentNodeName)) {
|
if (val != null && !val.equals(Main.currentNodeName)) {
|
||||||
SingleThreadedExecutor.execute(() -> Main.selectFile(val));
|
SingleThreadedExecutor.submit(() -> Main.selectFile(val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,16 +4,30 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
|
|
||||||
public class SingleThreadedExecutor {
|
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 LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
private static final Thread thread = new Thread(() -> {
|
private static final Thread thread = new Thread(() -> {
|
||||||
while (true) {
|
|
||||||
try {
|
try {
|
||||||
queue.take().run();
|
while (true) {
|
||||||
|
Runnable r = null;
|
||||||
|
synchronized (lock) {
|
||||||
|
while (runnable == null)
|
||||||
|
lock.wait();
|
||||||
|
r = runnable;
|
||||||
|
runnable = null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
r.run();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
}, "SingleThreadedExecutor");
|
}, "SingleThreadedExecutor");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -21,7 +35,10 @@ public class SingleThreadedExecutor {
|
|||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void execute(Runnable r) {
|
public static void submit(Runnable r) {
|
||||||
queue.add(r);
|
synchronized (lock) {
|
||||||
|
runnable = r;
|
||||||
|
lock.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -513,7 +513,7 @@ public class Main extends JFrame {
|
|||||||
});
|
});
|
||||||
scrollPane.setViewportView(tree);
|
scrollPane.setViewportView(tree);
|
||||||
tree.addTreeSelectionListener(e -> SingleThreadedExecutor
|
tree.addTreeSelectionListener(e -> SingleThreadedExecutor
|
||||||
.execute(() -> selectFile(((ByteEditTreeNode) e.getPath().getLastPathComponent()).path)));
|
.submit(() -> selectFile(((ByteEditTreeNode) e.getPath().getLastPathComponent()).path)));
|
||||||
new DropTarget(tree, new DropTargetListener() {
|
new DropTarget(tree, new DropTargetListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -606,7 +606,7 @@ public class Main extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
if (e.getKeyCode() == 116 && currentNodeName != null) { // F5
|
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) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
EnumDecompiler selected = (EnumDecompiler) e.getItem();
|
EnumDecompiler selected = (EnumDecompiler) e.getItem();
|
||||||
SingleThreadedExecutor.execute(() -> {
|
SingleThreadedExecutor.submit(() -> {
|
||||||
decompiler = selected;
|
decompiler = selected;
|
||||||
if (currentNodeName != null) {
|
if (currentNodeName != null) {
|
||||||
decompileCurrentNode();
|
decompileCurrentNode();
|
||||||
|
|||||||
Reference in new issue
Block a user