Java Scheduler ScheduledExecutorService ScheduledThreadPoolExecutor Example(ScheduledThreadPoolEx...

<div class="entry-content" itemprop="text"><!-- Quick Adsense WordPress Plugin: http://quickadsense.com/ --> <div style="float: none; margin:10px 0 10px 0; text-align:center;"> <div data-type="ad" data-publisher="journaldev.com" data-zone="jd\_after\_entry\_728x90" data-format="728x90"> </div> </div> <p>Welcome to the Java Scheduler Example. Today we will look into <code>ScheduledExecutorService</code> and it’s implementation class <code>ScheduledThreadPoolExecutor</code> example.</p> <div id="toc\_container" class="toc\_light\_blue no\_bullets"><p class="toc\_title">Table of Contents <span class="toc\_toggle">\[<a href="#">hide</a>\]</span></p><ul class="toc\_list"><li><a href="#java-scheduler-scheduledexecutorservice"><span class="toc\_number toc\_depth\_1">1</span> Java Scheduler ScheduledExecutorService</a><ul><li><a href="#java-scheduler-example"><span class="toc\_number toc\_depth\_2">1.1</span> Java Scheduler Example</a></li><li><a href="#scheduledexecutorservice-scheduleatfixedraterunnable-commandlong-initialdelaylong-periodtimeunit-unit"><span class="toc\_number toc\_depth\_2">1.2</span> ScheduledExecutorService scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)</a></li><li><a href="#scheduledexecutorservice-schedulewithfixeddelayrunnable-commandlong-initialdelaylong-delaytimeunit-unit"><span class="toc\_number toc\_depth\_2">1.3</span> ScheduledExecutorService scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)</a></li></ul></li></ul></div> <h2><span id="java-scheduler-scheduledexecutorservice">Java Scheduler ScheduledExecutorService</span></h2> <p><a href="https://my.oschina.net//cdn.journaldev.com/wp-content/uploads/2013/10/java-scheduler-example-scheduledexecutorservice-scheduledthreadpoolexecutor.jpg"><img src="https://my.oschina.net//cdn.journaldev.com/wp-content/uploads/2013/10/java-scheduler-example-scheduledexecutorservice-scheduledthreadpoolexecutor.jpg" alt="java scheduler, java scheduler example, ScheduledExecutorService, ScheduledThreadPoolExecutor" width="560" height="315" class="aligncenter size-full wp-image-12032" srcset="//cdn.journaldev.com/wp-content/uploads/2013/10/java-scheduler-example-scheduledexecutorservice-scheduledthreadpoolexecutor.jpg 560w, //cdn.journaldev.com/wp-content/uploads/2013/10/java-scheduler-example-scheduledexecutorservice-scheduledthreadpoolexecutor-450x253.jpg 450w, //cdn.journaldev.com/wp-content/uploads/2013/10/java-scheduler-example-scheduledexecutorservice-scheduledthreadpoolexecutor-20x11.jpg 20w" sizes="(max-width: 560px) 100vw, 560px"></a><br> Sometimes we need to execute a task periodically or after specific delay. Java provides <a href="https://www.journaldev.com/1050/java-timer-timertask-example"><strong>Timer Class</strong></a> through which we can achieve this but sometimes we need to run similar tasks in parallel. So creating multiple Timer objects will be an overhead to the system and it’s better to have a thread pool of scheduled tasks. </p> <p>Java provides scheduled thread pool implementation through <code>ScheduledThreadPoolExecutor</code> class that implements <code>ScheduledExecutorService</code> interface. ScheduledExecutorService defines the contract methods to schedule a task with different options.</p> <p>Sometime back I wrote a post about <a href="https://www.journaldev.com/1069/threadpoolexecutor-java-thread-pool-example-executorservice">Java ThreadPoolExecutor</a> where I was using Executors class to create the thread pool. Executors class also provide factory methods to create <strong>ScheduledThreadPoolExecutor</strong> where we can specify the number of threads in the pool.</p> <h3><span id="java-scheduler-example">Java Scheduler Example</span></h3> <p>Let’s say we have a simple Runnable class like below.</p> <p><code>WorkerThread.java</code></p> <!-- Quick Adsense WordPress Plugin: http://quickadsense.com/ --> <div style="float: none; margin:10px 0 10px 0; text-align:center;"> <div data-type="ad" data-publisher="journaldev.com" data-format="300x250" data-zone="jd\_post\_mid\_300x250"></div> </div> <pre style="display: block;"><code class="hljs java"><div class="re\_clip-board" style="display: none;">Copy</div> <span class="hljs-keyword">package</span> com.journaldev.threads; <span class="hljs-keyword">import</span> java.util.Date; <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">WorkerThread</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Runnable</span></span>{ <span class="hljs-keyword">private</span> String command; <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">WorkerThread</span><span class="hljs-params">(String s)</span></span>{ <span class="hljs-keyword">this</span>.command=s; } <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{ System.out.println(Thread.currentThread().getName()+<span class="hljs-string">" Start. Time = "</span>+<span class="hljs-keyword">new</span> Date()); processCommand(); System.out.println(Thread.currentThread().getName()+<span class="hljs-string">" End. Time = "</span>+<span class="hljs-keyword">new</span> Date()); } <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">processCommand</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">try</span> { Thread.sleep(<span class="hljs-number">5000</span>); } <span class="hljs-keyword">catch</span> (InterruptedException e) { e.printStackTrace(); } } <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">toString</span><span class="hljs-params">()</span></span>{ <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.command; } } </code></pre> <p>It’s a simple Runnable class that takes around 5 seconds to execute its task.</p> <p>Let’s see a simple example where we will schedule the worker thread to execute after 10 seconds delay. We will use Executors class <code>newScheduledThreadPool(int corePoolSize)</code> method that returns instance of <code>ScheduledThreadPoolExecutor</code>. Here is the code snippet from Executors class.</p> <pre style="display: block;"><code class="hljs cpp"><div class="re\_clip-board" style="display: none;">Copy</div><span class="hljs-function"> <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ScheduledExecutorService <span class="hljs-title">newScheduledThreadPool</span><span class="hljs-params">(<span class="hljs-keyword">int</span> corePoolSize)</span> </span>{ <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ScheduledThreadPoolExecutor(corePoolSize); } </code></pre> <p>Below is our java scheduler example program using <code>ScheduledExecutorService</code> and <code>ScheduledThreadPoolExecutor</code> implementation.</p> <pre style="display: block;"><code class="hljs java"><div class="re\_clip-board">Copy</div> <span class="hljs-keyword">package</span> com.journaldev.threads;

<span class="hljs-keyword">import</span> java.util.Date; <span class="hljs-keyword">import</span> java.util.concurrent.Executors; <span class="hljs-keyword">import</span> java.util.concurrent.ScheduledExecutorService; <span class="hljs-keyword">import</span> java.util.concurrent.TimeUnit;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ScheduledThreadPool</span> </span>{

1<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{ 2 ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(<span class="hljs-number">5</span>); 3 4 5 <span class="hljs-comment">//schedule to run after sometime</span> 6 System.out.println(<span class="hljs-string">"Current Time = "</span>+<span class="hljs-keyword">new</span> Date()); 7 <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-number">3</span>; i++){ 8 Thread.sleep(<span class="hljs-number">1000</span>); 9 WorkerThread worker = <span class="hljs-keyword">new</span> WorkerThread(<span class="hljs-string">"do heavy processing"</span>); 10 scheduledThreadPool.schedule(worker, <span class="hljs-number">10</span>, TimeUnit.SECONDS); 11 } 12 13 <span class="hljs-comment">//add some delay to let some threads spawn by scheduler</span> 14 Thread.sleep(<span class="hljs-number">30000</span>); 15 16 scheduledThreadPool.shutdown(); 17 <span class="hljs-keyword">while</span>(!scheduledThreadPool.isTerminated()){ 18 <span class="hljs-comment">//wait for all tasks to finish</span> 19 } 20 System.out.println(<span class="hljs-string">"Finished all threads"</span>); 21}

} </code></pre>

<p>When we run above java scheduler example program, we get following output that confirms that tasks are running with 10 seconds delay.</p> <!-- Quick Adsense WordPress Plugin: http://quickadsense.com/ --> <div style="float: none; margin:10px 0 10px 0; text-align:center;"> <div data-type="ad" data-publisher="journaldev.com" data-zone="jd\_leaderboard\_728x90" data-format="728x90"> </div> </div> <pre style="display: block;"><code class="hljs sql"><div class="re\_clip-board">Copy</div> Current Time = Tue Oct 29 15:10:03 IST 2013 pool-1-thread-1 Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">15</span>:<span class="hljs-number">10</span>:<span class="hljs-number">14</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-2</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">15</span>:<span class="hljs-number">10</span>:<span class="hljs-number">15</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-3</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">15</span>:<span class="hljs-number">10</span>:<span class="hljs-number">16</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-1</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">15</span>:<span class="hljs-number">10</span>:<span class="hljs-number">19</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-2</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">15</span>:<span class="hljs-number">10</span>:<span class="hljs-number">20</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-3</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">15</span>:<span class="hljs-number">10</span>:<span class="hljs-number">21</span> IST <span class="hljs-number">2013</span> Finished all threads </code></pre> <p>Note that all the <code>schedule()</code> methods return instance of <code>ScheduledFuture</code> that we can use to get the thread state information and delay time for the thread. </p> <!-- Quick Adsense WordPress Plugin: http://quickadsense.com/ --> <div style="float: none; margin:10px 0 10px 0; text-align:center;"> <!-- CM\_JD\_AP\_Middle\_Responsive --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5143693538742787" data-ad-slot="7174295726" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || \[\]).push({}); </script> </div> <p>ScheduledFuture extends Future interface, read more about them at <a href="https://www.journaldev.com/1090/java-callable-future-example">Java Callable Future Example</a>.</p> <p>There are two more methods in ScheduledExecutorService that provide option to schedule a task to run periodically.</p> <h3><span id="scheduledexecutorservice-scheduleatfixedraterunnable-commandlong-initialdelaylong-periodtimeunit-unit">ScheduledExecutorService scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)</span></h3> <p>We can use ScheduledExecutorService scheduleAtFixedRate method to schedule a task to run after initial delay and then with the given period. </p> <p>The time period is from the start of the first thread in the pool, so if you are specifying period as 1 second and your thread runs for 5 second, then the next thread will start executing as soon as the first worker thread finishes it’s execution.</p> <p>For example, if we have code like this:</p> <pre style="display: block;"><code class="hljs cpp"><div class="re\_clip-board"><span class="hljs-function">Copy</span></div><span class="hljs-function"> <span class="hljs-title">for</span> <span class="hljs-params">(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; i++)</span> </span>{ Thread.sleep(<span class="hljs-number">1000</span>); WorkerThread worker = <span class="hljs-keyword">new</span> WorkerThread(<span class="hljs-string">"do heavy processing"</span>); <span class="hljs-comment">// schedule task to execute at fixed rate</span> scheduledThreadPool.scheduleAtFixedRate(worker, <span class="hljs-number">0</span>, <span class="hljs-number">10</span>, TimeUnit.SECONDS); } </code></pre> <p>Then we will get output like below.</p> <pre style="display: block;"><code class="hljs sql"><div class="re\_clip-board">Copy</div> Current Time = Tue Oct 29 16:10:00 IST 2013 pool-1-thread-1 Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">01</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-2</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">02</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-3</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">03</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-1</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">06</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-2</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">07</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-3</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">08</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-1</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">11</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-4</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">10</span>:<span class="hljs-number">12</span> IST <span class="hljs-number">2013</span> </code></pre> <h3><span id="scheduledexecutorservice-schedulewithfixeddelayrunnable-commandlong-initialdelaylong-delaytimeunit-unit">ScheduledExecutorService scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit)</span></h3> <p>ScheduledExecutorService scheduleWithFixedDelay method can be used to start the periodic execution with initial delay and then execute with given delay. The delay time is from the time thread finishes it’s execution. So if we have code like below:</p> <pre style="display: block;"><code class="hljs cpp"><div class="re\_clip-board"><span class="hljs-function">Copy</span></div><span class="hljs-function"> <span class="hljs-title">for</span> <span class="hljs-params">(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; i++)</span> </span>{ Thread.sleep(<span class="hljs-number">1000</span>); WorkerThread worker = <span class="hljs-keyword">new</span> WorkerThread(<span class="hljs-string">"do heavy processing"</span>); scheduledThreadPool.scheduleWithFixedDelay(worker, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, TimeUnit.SECONDS); } </code></pre> <p>Then we will get output like below.</p> <pre style="display: block;"><code class="hljs sql"><div class="re\_clip-board">Copy</div> Current Time = Tue Oct 29 16:14:13 IST 2013 pool-1-thread-1 Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">14</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-2</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">15</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-3</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">16</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-1</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">19</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-2</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">20</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-1</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">20</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-3</span> End. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">21</span> IST <span class="hljs-number">2013</span> pool<span class="hljs-number">-1</span>-<span class="hljs-keyword">thread</span><span class="hljs-number">-4</span> Start. <span class="hljs-keyword">Time</span> = Tue <span class="hljs-keyword">Oct</span> <span class="hljs-number">29</span> <span class="hljs-number">16</span>:<span class="hljs-number">14</span>:<span class="hljs-number">21</span> IST <span class="hljs-number">2013</span> </code></pre> <p>That’s all for java scheduler example. We learned about ScheduledExecutorService and ScheduledThreadPoolExecutorthread too. You should check other articles about <a href="https://www.journaldev.com/1079/multithreading-in-java">Multithreading in Java</a>. </p> <p>References:</p> <ul> <li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html" target="\_blank">ScheduledExecutorService API Doc</a></li> <li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html" target="\_blank">ScheduledThreadPoolExecutor API Doc</a></li> </ul> <!-- Quick Adsense WordPress Plugin: http://quickadsense.com/ --> <div style="float: none; margin:0px 0 0px 0; text-align:center;"> <script async="" src="https://my.oschina.net//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5143693538742787" data-ad-slot="3941417857"></ins> <script> (adsbygoogle = window.adsbygoogle || \[\]).push({}); </script> </div> <div style="font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;"></div><div class="scriptlesssocialsharing"><div class="scriptlesssocialsharing-buttons"><a class="button twitter" target="\_blank" href="https://twitter.com/intent/tweet?text=Java%20Scheduler%20ScheduledExecutorService%20ScheduledThreadPoolExecutor%20Example&amp;url=https%3A%2F%2Fwww.journaldev.com%2F2340%2Fjava-scheduler-scheduledexecutorservice-scheduledthreadpoolexecutor-example&amp;via=JournalDev&amp;related=JournalDev" rel="noopener"><span class="sss-name">Twitter</span></a><a class="button facebook" target="\_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.journaldev.com%2F2340%2Fjava-scheduler-scheduledexecutorservice-scheduledthreadpoolexecutor-example" rel="noopener"><span class="sss-name">Facebook</span></a><a class="button linkedin" target="\_blank" href="https://www.linkedin.com/shareArticle?mini=1&amp;url=https%3A%2F%2Fwww.journaldev.com%2F2340%2Fjava-scheduler-scheduledexecutorservice-scheduledthreadpoolexecutor-example&amp;title=Java%20Scheduler%20ScheduledExecutorService%20ScheduledThreadPoolExecutor%20Example&amp;source=https://www.journaldev.com" rel="noopener"><span class="sss-name">Linkedin</span></a><a class="button email" target="\_blank" href="mailto:?body=I%20read%20this%20post%20and%20wanted%20to%20share%20it%20with%20you.%20Here's%20the%20link:%20https%3A%2F%2Fwww.journaldev.com%2F2340%2Fjava-scheduler-scheduledexecutorservice-scheduledthreadpoolexecutor-example&amp;subject=A%20post%20worth%20sharing:%20Java%20Scheduler%20ScheduledExecutorService%20ScheduledThreadPoolExecutor%20Example" rel="noopener"><span class="sss-name">Email</span></a></div></div><div class="prev-next-navigation"><a href="https://www.journaldev.com/2335/read-csv-file-java-scanner" rel="prev"><div class="previous"><span class="prev\_icon">&nbsp;Previous </span><br> <span class="pagi\_content">Read CSV File in Java using Scanner</span></div></a><a href="https://www.journaldev.com/2377/java-lock-example-reentrantlock" rel="next"><div class="next"><span class="next\_icon">Next&nbsp;</span><br> <span class="pagi\_content">Java Lock Example – ReentrantLock</span></div></a></div> <!-- .prev-next-navigation --><section class="author-box" itemprop="author" itemscope="" itemtype="https://schema.org/Person"><h4 class="author-box-title">About <span itemprop="name">Pankaj</span></h4><div class="author-box-content" itemprop="description"><p>If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on <a href="https://plus.google.com/118104420597648001532/posts?rel=author"><strong>Google Plus</strong></a>, <a href="https://www.facebook.com/journaldev"><strong>Facebook</strong></a> or <a href="https://twitter.com/JournalDev"><strong>Twitter</strong></a>. I would love to hear your thoughts and opinions on my articles directly.</p> <p>Recently I started creating video tutorials too, so do check out my videos on <a href="https://www.youtube.com/user/JournalDev"><strong>Youtube</strong></a>.</p> </div></section></div>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

java反射, 不看你可别后悔

<divid"content\_views"class"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,

AndroidStudio封装SDK的那些事

<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael

LocalDateTime计算时间差

<divclass"htmledit\_views"id"content\_views"<pLocalDateTime为java8的新特性之一<br</p<p<br</p<pLocalDateTime.now()获得当前时间<br</p<p</p<h5</h5<divstyle"marginleft