(String[] args)
| 20 | public class ConcurrencyGC { |
| 21 | |
| 22 | public static void main(String[] args) throws InterruptedException, InvocationTargetException { |
| 23 | try { |
| 24 | vtkJavaTesting.Initialize(args, true); |
| 25 | |
| 26 | // Setup working runnable |
| 27 | Runnable workingJob = new Runnable() { |
| 28 | public void run() { |
| 29 | try { |
| 30 | vtkUnstructuredGrid grid = new vtkUnstructuredGrid(); |
| 31 | grid.SetPoints(new vtkPoints()); |
| 32 | vtkPoints p; |
| 33 | long timeout = System.currentTimeMillis() + 60000; // +1 minute |
| 34 | while (System.currentTimeMillis() < timeout) { |
| 35 | p = grid.GetPoints(); |
| 36 | if (p == null) { |
| 37 | throw new RuntimeException("Invalid pointer null"); |
| 38 | } |
| 39 | if (p.GetReferenceCount() != 2) { |
| 40 | throw new RuntimeException("Invalid reference count of " + p.GetReferenceCount()); |
| 41 | } |
| 42 | } |
| 43 | } catch (Throwable e) { |
| 44 | e.printStackTrace(); |
| 45 | vtkJavaTesting.Exit(vtkJavaTesting.FAILED); |
| 46 | } |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | // Start threads for concurrency (2xwork + 1xGC + 1xGCinEDT) |
| 51 | Thread worker1 = new Thread(workingJob); |
| 52 | Thread worker2 = new Thread(workingJob); |
| 53 | |
| 54 | // Start working thread |
| 55 | worker1.start(); |
| 56 | worker2.start(); |
| 57 | |
| 58 | // Setup GC |
| 59 | vtkJavaGarbageCollector gc = vtkJavaTesting.StartGCInEDT(10, TimeUnit.MILLISECONDS); // Start periodic GC in EDT |
| 60 | new Thread(gc.GetDeleteRunnable()).start(); // Start GC in tight loop |
| 61 | |
| 62 | // If worker finished close everything |
| 63 | worker1.join(); |
| 64 | worker2.join(); |
| 65 | gc.Stop(); |
| 66 | vtkJavaTesting.Exit(vtkJavaTesting.PASSED); |
| 67 | |
| 68 | } catch (Throwable e) { |
| 69 | e.printStackTrace(); |
| 70 | vtkJavaTesting.Exit(vtkJavaTesting.FAILED); |
| 71 | } |
| 72 | } |
| 73 | } |
nothing calls this directly
no test coverage detected