Mercurial Hosting > luan
comparison src/luan/modules/ThreadLuan.java @ 782:655280eab1e2
start limited cloning
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 30 Aug 2016 01:29:33 -0600 |
parents | fbbdd369a13a |
children | d69d3c51c44e |
comparison
equal
deleted
inserted
replaced
781:fbbdd369a13a | 782:655280eab1e2 |
---|---|
17 public final class ThreadLuan { | 17 public final class ThreadLuan { |
18 private static final Executor exec = Executors.newCachedThreadPool(); | 18 private static final Executor exec = Executors.newCachedThreadPool(); |
19 private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); | 19 private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); |
20 | 20 |
21 public static void fork(LuanState luan,LuanFunction fn,Object... args) { | 21 public static void fork(LuanState luan,LuanFunction fn,Object... args) { |
22 LuanCloner cloner = new LuanCloner(); | 22 LuanCloner cloner = new LuanCloner(true); |
23 final LuanState newLuan = (LuanState)cloner.deepClone(luan); | 23 final LuanState newLuan = (LuanState)cloner.clone(luan); |
24 final LuanFunction newFn = (LuanFunction)cloner.get(fn); | 24 final LuanFunction newFn = (LuanFunction)cloner.get(fn); |
25 final Object[] newArgs = cloner.deepClone(args); | 25 final Object[] newArgs = cloner.clone(args); |
26 exec.execute(new Runnable(){public void run() { | 26 exec.execute(new Runnable(){public void run() { |
27 try { | 27 try { |
28 newFn.call(newLuan,newArgs); | 28 newFn.call(newLuan,newArgs); |
29 } catch(LuanException e) { | 29 } catch(LuanException e) { |
30 e.printStackTrace(); | 30 e.printStackTrace(); |
42 } | 42 } |
43 }; | 43 }; |
44 } | 44 } |
45 | 45 |
46 public static void schedule(LuanState luan,long delay,boolean repeat,LuanFunction fn,Object... args) { | 46 public static void schedule(LuanState luan,long delay,boolean repeat,LuanFunction fn,Object... args) { |
47 LuanCloner cloner = new LuanCloner(); | 47 LuanCloner cloner = new LuanCloner(true); |
48 final LuanState newLuan = (LuanState)cloner.deepClone(luan); | 48 final LuanState newLuan = (LuanState)cloner.clone(luan); |
49 final LuanFunction newFn = (LuanFunction)cloner.get(fn); | 49 final LuanFunction newFn = (LuanFunction)cloner.get(fn); |
50 final Object[] newArgs = cloner.deepClone(args); | 50 final Object[] newArgs = cloner.clone(args); |
51 Runnable r = new Runnable(){public void run() { | 51 Runnable r = new Runnable(){public void run() { |
52 try { | 52 try { |
53 newFn.call(newLuan,newArgs); | 53 newFn.call(newLuan,newArgs); |
54 } catch(LuanException e) { | 54 } catch(LuanException e) { |
55 e.printStackTrace(); | 55 e.printStackTrace(); |