// Scala program to implement multi-tasking // using thread class MyThread extends Thread { override def run() { var cnt: Int = 0; while (cnt < 5) { println("###cnt: " + cnt); Thread.sleep(100); cnt = cnt + 1; } } def myTask() { var cnt: Int = 0; while (cnt < ...
importjava.util.concurrent.atomic.AtomicReference;interfaceSpinLock {publicvoidlock();publicvoidunlock(); }publicclassMain {privatestaticclassNonReentrantSpinLockimplementsSpinLock {privateAtomicReference<Thread> owner =newAtomicReference<Thread>();publicvoidlock() {ThreadcurrentThread =Thread.currentThread();while...
pdai@MacBook-Pro apache-shardingsphere-elasticjob-3.0.1-lite-ui-bin % vi bin/start.sh pdai@MacBook-Pro apache-shardingsphere-elasticjob-3.0.1-lite-ui-bin % bin/start.sh Starting the ShardingSphere-ElasticJob-UI ... Please check the STDOUT file: /Users/pdai/apache-shardingsphere-elasticjob...
Thread.sleep(1000); // throw exception if the last re-try fails if (i == MAX_RETRIES) { throw ex; } } } } } Download Run Code Output (will vary): Random number is.. 0 / by zero Random number is.. 0 / by zero Random number is.. 1 2. Using Interface We can easily tweak...
As I said before using lambdas to implement a Comparator is a good way to learn how lambda expression works in Java. Since lambda expression in Java is SAM type (Single Abstract Method) you can use it with any interface which got just one method likeComparator,Comparable,Runnable,Callable,Act...
setThreadNamePrefix("idleMonitor"); scheduler.setPoolSize(5); return scheduler; } @Bean public CloseableHttpClient httpClient() { RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(CONNECTION_TIMEOUT) .setConnectionRequestTimeout(REQUEST_TIMEOUT) .setSocketTimeout(SOCKET_TIMEOUT) ...