ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/util/Task.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/util/Task.java
Status
scanned
Type
file
Name
Task.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
2867 (2.8 KB)
MD5
20f744e480345a90ed4a82ecf5754fc7
SHA1
ccdf344f70f94602a70d8c34a2ca12a0eb057f52
SHA256
dff83e2c882384b4dc5715baecd430a508e7543cef13e2086e0cf164e2753b82
SHA512

      
    
SHA1_git
c96d0d95c2470eab34bee51afb9c1cae05a895b6
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
Task.java | 2.8 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.util; import java.util.concurrent.atomic.AtomicInteger; /** * A method call that is executed in a separate thread. If the method throws an * exception, it is wrapped in a RuntimeException. */ public abstract class Task implements Runnable { private static final AtomicInteger counter = new AtomicInteger(); /** * A flag indicating the get() method has been called. */ public volatile boolean stop; /** * The result, if any. */ private volatile Object result; private volatile boolean finished; private Thread thread; private volatile Exception ex; /** * The method to be implemented. * * @throws Exception any exception is wrapped in a RuntimeException */ public abstract void call() throws Exception; @Override public void run() { try { call(); } catch (Exception e) { this.ex = e; } finished = true; } /** * Start the thread. * * @return this */ public Task execute() { return execute(getClass().getName() + ":" + counter.getAndIncrement()); } /** * Start the thread. * * @param threadName the name of the thread * @return this */ public Task execute(String threadName) { thread = new Thread(this, threadName); thread.setDaemon(true); thread.start(); return this; } /** * Calling this method will set the stop flag and wait until the thread is * stopped. * * @return the result, or null * @throws RuntimeException if an exception in the method call occurs */ public Object get() { Exception e = getException(); if (e != null) { throw new RuntimeException(e); } return result; } /** * Whether the call method has returned (with or without exception). * * @return true if yes */ public boolean isFinished() { return finished; } /** * Get the exception that was thrown in the call (if any). * * @return the exception or null */ public Exception getException() { join(); if (ex != null) { return ex; } return null; } /** * Stop the thread and wait until it is no longer running. Exceptions are * ignored. */ public void join() { stop = true; if (thread == null) { throw new IllegalStateException("Thread not started"); } try { thread.join(); } catch (InterruptedException e) { // ignore } } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
3.02
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220