Mercurial Hosting > luan
comparison src/luan/modules/ThreadLuan.java @ 1439:67bed466460e
minor logging
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 24 Jan 2020 06:09:50 -0500 |
parents | 225808b90cee |
children | 4e50b78c7040 |
comparison
equal
deleted
inserted
replaced
1438:a47021c3da1e | 1439:67bed466460e |
---|---|
52 exec.execute(runnable(newFn)); | 52 exec.execute(runnable(newFn)); |
53 } | 53 } |
54 | 54 |
55 private static Map<String,Reference<ScheduledFuture>> scheduleds = new ConcurrentHashMap<String,Reference<ScheduledFuture>>(); | 55 private static Map<String,Reference<ScheduledFuture>> scheduleds = new ConcurrentHashMap<String,Reference<ScheduledFuture>>(); |
56 | 56 |
57 private static void cancel(ScheduledFuture sf) { | |
58 boolean b = sf.cancel(false); | |
59 if( !b ) | |
60 logger.error("cancel failed"); | |
61 } | |
62 | |
57 public static void schedule(LuanFunction fn,LuanTable options) | 63 public static void schedule(LuanFunction fn,LuanTable options) |
58 throws LuanException | 64 throws LuanException |
59 { | 65 { |
60 options = new LuanTable(options); | 66 options = new LuanTable(options); |
61 Number delay = Utils.removeNumber(options,"delay"); | 67 Number delay = Utils.removeNumber(options,"delay"); |
69 if( id != null ) { | 75 if( id != null ) { |
70 Reference<ScheduledFuture> ref = scheduleds.remove(id); | 76 Reference<ScheduledFuture> ref = scheduleds.remove(id); |
71 if( ref != null ) { | 77 if( ref != null ) { |
72 ScheduledFuture sf = ref.get(); | 78 ScheduledFuture sf = ref.get(); |
73 if( sf != null ) | 79 if( sf != null ) |
74 sf.cancel(false); | 80 cancel(sf); |
75 } | 81 } |
76 } | 82 } |
77 Luan luan = fn.luan(); | 83 Luan luan = fn.luan(); |
78 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); | 84 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); |
79 final Luan newLuan = (Luan)cloner.clone(luan); | 85 final Luan newLuan = (Luan)cloner.clone(luan); |
94 scheduler.schedule(r,0L,TimeUnit.MILLISECONDS); | 100 scheduler.schedule(r,0L,TimeUnit.MILLISECONDS); |
95 return; | 101 return; |
96 } | 102 } |
97 Object c = new Object() { | 103 Object c = new Object() { |
98 protected void finalize() throws Throwable { | 104 protected void finalize() throws Throwable { |
99 sf.cancel(false); | 105 cancel(sf); |
100 } | 106 } |
101 }; | 107 }; |
102 luan.registry().put(c,c); // cancel on gc | 108 luan.registry().put(c,c); // cancel on gc |
103 if( id != null ) | 109 if( id != null ) |
104 scheduleds.put(id,new WeakReference<ScheduledFuture>(sf)); | 110 scheduleds.put(id,new WeakReference<ScheduledFuture>(sf)); |