Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Thread Creation to ThreadFactory for better Thread namings #466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/version/v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void run() {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
```

Expand Down Expand Up @@ -443,7 +443,7 @@ class BasicThread implements Runnable {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/version/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void run() {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
```

Expand Down Expand Up @@ -443,7 +443,7 @@ class BasicThread implements Runnable {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/version/v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public void run() {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
```

Expand Down Expand Up @@ -497,7 +497,7 @@ class BasicThread implements Runnable {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
```

Expand Down
27 changes: 13 additions & 14 deletions src/main/java/net/coreprotect/CoreProtect.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package net.coreprotect;

import java.io.File;
import java.util.Iterator;
import java.util.Map.Entry;

import org.bstats.bukkit.MetricsLite;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

import net.coreprotect.command.CommandHandler;
import net.coreprotect.command.TabHandler;
import net.coreprotect.config.Config;
Expand All @@ -30,6 +18,17 @@
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Teleport;
import net.coreprotect.utility.Util;
import org.bstats.bukkit.MetricsLite;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.Iterator;
import java.util.Map.Entry;

public final class CoreProtect extends JavaPlugin {

Expand Down Expand Up @@ -102,15 +101,15 @@ public void onEnable() {

Scheduler.scheduleSyncDelayedTask(this, () -> {
try {
Thread networkHandler = new Thread(new NetworkHandler(true, true));
Thread networkHandler = Util.THREAD_FACTORY.newThread(new NetworkHandler(true, true));
networkHandler.start();
}
catch (Exception e) {
e.printStackTrace();
}
}, 0);

Thread cacheCleanUpThread = new Thread(new CacheHandler());
Thread cacheCleanUpThread = Util.THREAD_FACTORY.newThread(new CacheHandler());
cacheCleanUpThread.start();

Consumer.startConsumer();
Expand Down
35 changes: 14 additions & 21 deletions src/main/java/net/coreprotect/command/CommandHandler.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
package net.coreprotect.command;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
Expand All @@ -30,6 +10,19 @@
import net.coreprotect.utility.Chat;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class CommandHandler implements CommandExecutor {
private static CommandHandler instance;
Expand Down Expand Up @@ -1269,7 +1262,7 @@ public void run() {
}
}
}
(new Thread(new updateAlert())).start();
(Util.THREAD_FACTORY.newThread(new updateAlert())).start();
}
}

Expand Down
52 changes: 23 additions & 29 deletions src/main/java/net/coreprotect/command/LookupCommand.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
package net.coreprotect.command;

import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.Statement;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import com.google.common.base.Strings;

import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.Database;
import net.coreprotect.database.Lookup;
import net.coreprotect.database.logger.ItemLogger;
import net.coreprotect.database.lookup.BlockLookup;
import net.coreprotect.database.lookup.ChestTransactionLookup;
import net.coreprotect.database.lookup.InteractionLookup;
import net.coreprotect.database.lookup.PlayerLookup;
import net.coreprotect.database.lookup.SignMessageLookup;
import net.coreprotect.database.lookup.*;
import net.coreprotect.database.statement.UserStatement;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
Expand All @@ -41,6 +16,25 @@
import net.coreprotect.utility.ChatMessage;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.Statement;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class LookupCommand {
protected static void runCommand(CommandSender player, Command command, boolean permission, String[] args) {
Expand Down Expand Up @@ -375,7 +369,7 @@ public void run() {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
}
else if (type == 2 || type == 3 || type == 7 || type == 8) {
Expand Down Expand Up @@ -495,7 +489,7 @@ else if (blockdata.length() > 0) {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
}
else if (type == 4 || type == 5) {
Expand Down Expand Up @@ -1096,7 +1090,7 @@ else if (rows > 0) {
}
}
Runnable runnable = new BasicThread2();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
}
catch (Exception e) {
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/net/coreprotect/command/PurgeCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
package net.coreprotect.command;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;

import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.Consumer;
Expand All @@ -24,6 +11,18 @@
import net.coreprotect.utility.ChatMessage;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Util;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;

public class PurgeCommand extends Consumer {

Expand Down Expand Up @@ -386,7 +385,7 @@ else if (argWid > 0) {
}

Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
}
}
8 changes: 4 additions & 4 deletions src/main/java/net/coreprotect/command/ReloadCommand.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.coreprotect.command;

import org.bukkit.command.CommandSender;

import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.language.Phrase;
import net.coreprotect.thread.NetworkHandler;
import net.coreprotect.utility.Chat;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Util;
import org.bukkit.command.CommandSender;

public class ReloadCommand {
protected static void runCommand(final CommandSender player, boolean permission, String[] args) {
Expand Down Expand Up @@ -44,7 +44,7 @@ public void run() {
ConfigHandler.performInitialization(false);
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.RELOAD_SUCCESS));

Thread networkHandler = new Thread(new NetworkHandler(false, false));
Thread networkHandler = Util.THREAD_FACTORY.newThread(new NetworkHandler(false, false));
networkHandler.start();
}
catch (Exception e) {
Expand All @@ -56,7 +56,7 @@ public void run() {
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
}
else {
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/net/coreprotect/command/RollbackRestoreCommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package net.coreprotect.command;

import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.ContainerRollback;
import net.coreprotect.database.Database;
import net.coreprotect.database.Rollback;
import net.coreprotect.database.lookup.PlayerLookup;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.utility.Chat;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -19,17 +23,12 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.ContainerRollback;
import net.coreprotect.database.Database;
import net.coreprotect.database.Rollback;
import net.coreprotect.database.lookup.PlayerLookup;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.utility.Chat;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Util;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class RollbackRestoreCommand {
protected static void runCommand(CommandSender player, Command command, boolean permission, String[] args, Location argLocation, long forceStart, long forceEnd) {
Expand Down Expand Up @@ -458,7 +457,7 @@ else if (action == 0) {
}
}
Runnable runnable = new BasicThread2();
Thread thread = new Thread(runnable);
Thread thread = Util.THREAD_FACTORY.newThread(runnable);
thread.start();
}
catch (Exception e) {
Expand Down
Loading