-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c41a28
commit 8570236
Showing
5 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/de/oliver/fancynpcs/skins/MineSkinQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.oliver.fancynpcs.skins; | ||
|
||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class MineSkinQueue { | ||
|
||
private final static ScheduledExecutorService EXECUTOR = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder() | ||
.setNameFormat("MineSkinQueue") | ||
.build()); | ||
private static MineSkinQueue INSTANCE; | ||
private final Queue<Runnable> queue; | ||
|
||
private MineSkinQueue() { | ||
this.queue = new LinkedList<>(); | ||
|
||
run(); | ||
} | ||
|
||
public static MineSkinQueue get() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new MineSkinQueue(); | ||
} | ||
|
||
return INSTANCE; | ||
} | ||
|
||
public void add(Runnable runnable) { | ||
this.queue.add(runnable); | ||
} | ||
|
||
private void run() { | ||
EXECUTOR.scheduleAtFixedRate(this::poll, 5, 60, TimeUnit.SECONDS); | ||
} | ||
|
||
private void poll() { | ||
System.out.println("Polling queue"); | ||
if (this.queue.isEmpty()) { | ||
return; | ||
} | ||
|
||
System.out.println("Running runnables"); | ||
int counter = 0; | ||
while (!this.queue.isEmpty() && counter < 9) { | ||
Runnable runnable = this.queue.poll(); | ||
if (runnable != null) { | ||
runnable.run(); | ||
} | ||
counter++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters