Add basis of grouped thread factory and make the scheduler use it.

This commit is contained in:
md_5
2014-07-10 11:09:59 +10:00
parent 6615500f08
commit 705b554b3b
5 changed files with 63 additions and 14 deletions

View File

@@ -1,11 +1,16 @@
package net.md_5.bungee.api.plugin;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.io.File;
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.logging.Logger;
import lombok.Getter;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ConfigurationAdapter;
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
/**
* Represents any Plugin that may be loaded at runtime to enhance existing
@@ -83,4 +88,19 @@ public class Plugin
this.file = description.getFile();
this.logger = new PluginLogger( this );
}
//
private ExecutorService service;
@Deprecated
public ExecutorService getExecutorService()
{
if ( service == null )
{
service = Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat( getDescription().getName() + " Pool Thread #%1$d" )
.setThreadFactory( new GroupedThreadFactory( this ) ).build() );
}
return service;
}
//
}

View File

@@ -0,0 +1,34 @@
package net.md_5.bungee.api.scheduler;
import java.util.concurrent.ThreadFactory;
import lombok.Data;
import net.md_5.bungee.api.plugin.Plugin;
@Data
@Deprecated
public class GroupedThreadFactory implements ThreadFactory
{
private final ThreadGroup group;
public class BungeeGroup extends ThreadGroup
{
private BungeeGroup(String name)
{
super( name );
}
}
public GroupedThreadFactory(Plugin plugin)
{
this.group = new BungeeGroup( plugin.getDescription().getName() );
}
@Override
public Thread newThread(Runnable r)
{
return new Thread( group, r );
}
}