dengxinyi 6 年之前
父节点
当前提交
e6e848902f
共有 3 个文件被更改,包括 51 次插入0 次删除
  1. 23 0
      oj/concurrent/TestCallable.java
  2. 19 0
      oj/concurrent/TestRunnable.java
  3. 9 0
      oj/oo-design/classloader/Main.java

+ 23 - 0
oj/concurrent/TestCallable.java

@@ -0,0 +1,23 @@
+import java.util.concurrent.*;
+
+public class TestCallable {
+    public static void main(String[] args) throws Exception {
+        MyCallable callable = new MyCallable();
+        FutureTask<String> future = new FutureTask<>(callable);
+        Thread thread = new Thread(future);
+        thread.start();
+        System.out.println(future.get());
+    }
+}
+
+class MyCallable implements Callable<String> {
+    @Override
+    public String call() {
+        try {
+            Thread.sleep(1000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "Finished.";
+    }
+}

+ 19 - 0
oj/concurrent/TestRunnable.java

@@ -0,0 +1,19 @@
+public class TestRunnable {
+    public static void main(String[] args) {
+        MyRunnable runnable = new MyRunnable();
+        Thread thread = new Thread(runnable);
+        thread.start();
+    }
+}
+
+class MyRunnable implements Runnable {
+    @Override
+    public void run() {
+        try {
+            Thread.sleep(1000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        System.out.println("Finished.");
+    }
+}

+ 9 - 0
oj/oo-design/classloader/Main.java

@@ -0,0 +1,9 @@
+package sun.applet;
+
+public class Main {
+    public Main() {}
+
+    public static void main(String[] args) {
+        System.out.println("Test class loader.");
+    }
+}