Skip to content

Commit

Permalink
Use daemon threads in executor service (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
w3stling authored Aug 10, 2024
1 parent a810b7e commit 5a37e22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.apptasticsoftware.rssreader;

import com.apptasticsoftware.rssreader.util.Mapper;
import com.apptasticsoftware.rssreader.util.DaemonThreadFactory;

import javax.net.ssl.SSLContext;
import javax.xml.stream.XMLInputFactory;
Expand Down Expand Up @@ -64,7 +65,7 @@
*/
public abstract class AbstractRssReader<C extends Channel, I extends Item> {
private static final String LOG_GROUP = "com.apptasticsoftware.rssreader";
private static final ScheduledThreadPoolExecutor EXECUTOR = new ScheduledThreadPoolExecutor(1);
private static final ScheduledExecutorService EXECUTOR = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("RssReaderWorker"));
private final HttpClient httpClient;
private DateTimeParser dateTimeParser = new DateTime();
private String userAgent = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.apptasticsoftware.rssreader.util;

import java.util.concurrent.ThreadFactory;

/**
* Thread factory that creates daemon threads
*/
public class DaemonThreadFactory implements ThreadFactory {
private final String name;
private int counter;

public DaemonThreadFactory(String name) {
this.name = name;
}

@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, name + "-" + counter++);
t.setDaemon(true);
return t;
}

}

0 comments on commit 5a37e22

Please sign in to comment.