Updated checkstyle errors.
This commit is contained in:
parent
52a81eb368
commit
d6b5456f98
@ -71,17 +71,17 @@ public class App {
|
|||||||
LOGGER.info("All the TaskGenerators started.");
|
LOGGER.info("All the TaskGenerators started.");
|
||||||
|
|
||||||
// Create three TaskGenerator threads. Each of them will submit different number of jobs.
|
// Create three TaskGenerator threads. Each of them will submit different number of jobs.
|
||||||
Runnable taskRunnable_1 = new TaskGenerator(msgQueue, 5);
|
Runnable taskRunnable1 = new TaskGenerator(msgQueue, 5);
|
||||||
Runnable taskRunnable_2 = new TaskGenerator(msgQueue, 1);
|
Runnable taskRunnable2 = new TaskGenerator(msgQueue, 1);
|
||||||
Runnable taskRunnable_3 = new TaskGenerator(msgQueue, 2);
|
Runnable taskRunnable3 = new TaskGenerator(msgQueue, 2);
|
||||||
|
|
||||||
Thread taskGenerator_1 = new Thread(taskRunnable_1, "Task_Generator_1");
|
Thread taskGenerator1 = new Thread(taskRunnable1, "Task_Generator_1");
|
||||||
Thread taskGenerator_2 = new Thread(taskRunnable_2, "Task_Generator_2");
|
Thread taskGenerator2 = new Thread(taskRunnable2, "Task_Generator_2");
|
||||||
Thread taskGenerator_3 = new Thread(taskRunnable_3, "Task_Generator_3");
|
Thread taskGenerator3 = new Thread(taskRunnable3, "Task_Generator_3");
|
||||||
|
|
||||||
taskGenerator_1.start();
|
taskGenerator1.start();
|
||||||
taskGenerator_2.start();
|
taskGenerator2.start();
|
||||||
taskGenerator_3.start();
|
taskGenerator3.start();
|
||||||
|
|
||||||
LOGGER.info("Service Executor started.");
|
LOGGER.info("Service Executor started.");
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ public class App {
|
|||||||
Runnable srvRunnable = new ServiceExecutor(msgQueue);
|
Runnable srvRunnable = new ServiceExecutor(msgQueue);
|
||||||
Thread srvExec = new Thread(srvRunnable, "Service_Executor_Thread");
|
Thread srvExec = new Thread(srvRunnable, "Service_Executor_Thread");
|
||||||
srvExec.start();
|
srvExec.start();
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,14 +48,13 @@ public class MessageQueue {
|
|||||||
/**
|
/**
|
||||||
* All the TaskGenerator threads will call this method to insert the
|
* All the TaskGenerator threads will call this method to insert the
|
||||||
* Messages in to the Blocking Queue.
|
* Messages in to the Blocking Queue.
|
||||||
* @param msg
|
|
||||||
*/
|
*/
|
||||||
public void submitMsg(Message msg) {
|
public void submitMsg(Message msg) {
|
||||||
try {
|
try {
|
||||||
if(null != msg) {
|
if (null != msg) {
|
||||||
blkQueue.add(msg);
|
blkQueue.add(msg);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,8 +67,8 @@ public class MessageQueue {
|
|||||||
public Message retrieveMsg() {
|
public Message retrieveMsg() {
|
||||||
Message retrievedMsg = null;
|
Message retrievedMsg = null;
|
||||||
try {
|
try {
|
||||||
retrievedMsg = blkQueue.poll();
|
retrievedMsg = blkQueue.poll();
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,10 +47,10 @@ public class ServiceExecutor implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while(true) {
|
while (true) {
|
||||||
Message msg = msgQueue.retrieveMsg();
|
Message msg = msgQueue.retrieveMsg();
|
||||||
|
|
||||||
if(null != msg) {
|
if (null != msg) {
|
||||||
LOGGER.info(msg.toString() + " is served.");
|
LOGGER.info(msg.toString() + " is served.");
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("ServiceExecutor: All tasks are executed. Waiting.");
|
LOGGER.info("ServiceExecutor: All tasks are executed. Waiting.");
|
||||||
@ -58,9 +58,9 @@ public class ServiceExecutor implements Runnable {
|
|||||||
|
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
LOGGER.error(ie.getMessage());
|
LOGGER.error(ie.getMessage());
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class TaskGenerator implements Task, Runnable {
|
|||||||
public void submit(Message msg) {
|
public void submit(Message msg) {
|
||||||
try {
|
try {
|
||||||
this.msgQueue.submitMsg(msg);
|
this.msgQueue.submitMsg(msg);
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ public class TaskGenerator implements Task, Runnable {
|
|||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while(this.msgCount > 0) {
|
while (this.msgCount > 0) {
|
||||||
String statusMsg = "Message-" + this.msgCount + " submitted by " + Thread.currentThread().getName();
|
String statusMsg = "Message-" + this.msgCount + " submitted by " + Thread.currentThread().getName();
|
||||||
Message newMessage = new Message(statusMsg);
|
Message newMessage = new Message(statusMsg);
|
||||||
this.submit(newMessage);
|
this.submit(newMessage);
|
||||||
@ -78,9 +78,9 @@ public class TaskGenerator implements Task, Runnable {
|
|||||||
// Make the current thread to sleep after every Message submission.
|
// Make the current thread to sleep after every Message submission.
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
LOGGER.error(ie.getMessage());
|
LOGGER.error(ie.getMessage());
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user