java - can't find out how to use thread pools? -
Then, I need to modify a I do not need any fancy stuff, just change the Here's a simple example: There are several different implementations in this example using the In 2004, Editing Service was added, 1.5 is particularly complex with very little code but it solves the common problem. bank server Java class for the project, Uses I have to replace it with the
thread pool but tutorials for thread pools are extremely confusing and no one can tell how to create just one thread pool. For reference I am amending the thing which I am amending
public static zero main (string [] args) IOException {ArrayList accountList; Final difference ACCOUNTS_LENGTH = 10; Bank Bank = new bank (ACCOUNTS_LENGTH); Last full SBAP_PORT = 8888; ServerSocket Server = New Server Socket (SBAP_PORT); System.out.println ("The client is waiting to connect ..."); While (true) {socket s = server.accept (); System.out.println ("Client Connected."); Bank Service Services = New Bank Service (S, Bank); Thread t = new thread (service); T.start (); }
thread t to
thread pool , but if it's a Simple class is said that I can not find it.
What you are looking for is the executable service
import java.util.concurrent.Executors; Import java.util.concurrent.ScheduledExecutorService; Import java.util.concurrent.TimeUnit; Public Class Scheduled Line (Last String [] AGR) {Final Int Newtask = 10; Last Scheduled Exclusion Service SE = Executor NEESELETED SHEDPOOL (RuntimeGetReight). Available processor ()); (Ses.scheduleAtFixedRate (New MyRunnable (i), 0, 10, TimeUnit.SECONDS);}} Private Static Class MyRunnable Tools Runnables {Private Ent ID for (Int i = 0; i & lt; numTasks; i ++) ; Private int numbers; Private MyRunnable (last INAD) {this.id = id; This.numRuns = 0;} Override Public Wide Run () {this.numRuns + = 1; System.out.format ("% d - % D \ n ", this.id, this.numRuns);}}}
ScheduleExecutorService Which do different things for different situations
Comments
Post a Comment