Как обрабатывать пул потоков, где выполняется опрос, а другой должен обновлять новые входящие данные после обработки. Выполнения программы существ в классе контроллера, который имеет основной метод и пул потоков:Обращение с файловыми путями & wait notifyALL()
Главный контроллер класса
public static void main(String[] args) throws InterruptedException {
RunnableController controller = new RunnableController();
Accumulator acque = new Accumulator();
controller.initializeDb();
controller.initialiseThreads(acque);
controller.initialUpdate(acque);
}
Метод Run для опроса класса:
public void run() {
int seqId = 0;
List<KpiMessage> list = null;
while(true) {
try{
list = fullPoll(seqId);
if (!list.isEmpty()) {
accumulator.manageIngoing(list);
}
} catch (Exception e){
e.printStackTrace();
}
}
}
public List<KpiMessage> fullPoll(int lastSeq) throws Exception {
Statement st = dbConnection.createStatement();
System.out.println("Polling");
ResultSet rs = st.executeQuery("Select * from msg_new_to_bde where ACTION = 804 and SEQ >" +
lastSeq + "order by SEQ DESC");
return pojoCol;
}
метод Run для обработка:
public void run() {
try {
generate(accumulator.outgoingQueue);
accumulator.manageOutgoing(accumulator.outgoingQueue, dbConnection);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Способ обновления ать в базу данных
public void updateDb(Collection<KpiMessage> updatedQueue, Connection dbConnection) throws
SQLException{
for(KpiMessage pojoClass : updatedQueue){
Statement stmtupd = dbConnection.createStatement();
System.out.println("Updating");
String query = "UPDATE msg_new_to_bde SET KEYINFO1= 'Processed', KEYINFO2 = 'Updated'
WHERE ACTION = 804";
stmtupd.executeUpdate(query);**My Execution stops here**
Наконец класс аккумулятор для всех этих сохранением очередей:
public boolean isUsed = false;
public synchronized void manageIngoing(List<KpiMessage> list){
if(this.isUsed){
try {
wait();
System.out.println("first wait");
} catch (Exception e1) {
e1.printStackTrace();
}
}
System.out.println("recived pass after update");
this.getIncomingQueue().addAll(list);
//incoming queue copied to outgoing queue
this.setOutgoingQueue(this.getIncomingQueue());
System.out.println("waiting");
System.out.println("new incoming message");
this.isUsed = false;
notifyAll();
}
/**
* Method which handles synchronization using wait and notify for outgoing messages after
polling
* @param outgoingQueue
* @param dbConnection
*/
public synchronized void manageOutgoing(Collection<KpiMessage> outgoingQueue, Connection
dbConnection){
if(!this.isUsed)
{
try {
System.out.println("second wait");
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
this.isUsed = true;
DBhandler dbhandler = new DBhandler();
try {
dbhandler.updateDb(getOutgoingQueue(), dbConnection);
} catch (SQLException e) {
e.printStackTrace();
}
notifyAll();
}
}
Моя задача и вопрос:
1. Контроллер должен обрабатывать обе нити Poller & процессор и аккумулятор обрабатывают входящие и исходящие очереди, а затем загружаются в обновленную очередь для обновления БД после обработки
2.My класс здесь просто делает опрос один раз, не может обновляться, выполнение останавливается на
3.Is мой wait(), notifyALL() обрабатывает здесь.
Как добиться повторного опроса и обновления здесь?
Прошу прощения, но вам нужно суммировать или разделить его на разные вопросы отдельно, а не сразу сразу. – Jatin
@JAtin Я обновил, как вы уже сказали ... – Babu
@Jatin Мое execturtion точно останавливается на обновлении stament, который делает nto возвратом к looping также ... – Babu