Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

ConcurrentModificationException on Thread

Jet Beray
7 years ago Feb 11, 2016 6:57am
Jet Beray
7 years ago Feb 11, 2016 7:01am
Agata Vackova
7 years ago Feb 11, 2016 7:26am
Jet Beray
7 years ago Feb 12, 2016 6:24am
Agata Vackova
7 years ago Feb 12, 2016 7:32am
Jet Beray
7 years ago Feb 12, 2016 7:42am
Agata Vackova
7 years ago Feb 12, 2016 8:30am
PayrollDataGridProperties payroll = new PayrollDataGridProperties(); //GRID

generateBtn.addClickListener((Button.ClickEvent event) -> {
payroll.getContainerDataSource().removeAllItems();
try {
MyRunnable run = new MyRunnable();
Thread t = new Thread(run);
t.start();
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(PayrollByGroupUI.class.getName()).log(Level.SEVERE, null, ex);
}
UI.getCurrent().setPollInterval(500);
});

void processPayroll(int employeeId){
Employee e = es.findEmployeeById(employeeId);
double basicSalary = cps.findMonthlySalary(cps.findSalaryGrade(
pcps.findPCP(
e.getPositionClassificationPlanId()).getCompensationPlanID()).getSalaryGrade(),
e.getCompensationPlanStep(),
CommonUtil.convertStringToInteger(sslComboBox.getValue().toString()));
double taxableSalary = atacs.taxableSalary(basicSalary, e.getDependent())/12;
double grossAmount = basicSalary + PayrollConstants.PERA;
double withholding = atacs.monthlyTaxDue(taxableSalary, e.getDependent());
double rlip = atacs.monthlyGsis(basicSalary);
double phic = atacs.monthlyPhic(basicSalary);
double hdmf = atacs.monthlyHdmf(basicSalary);
double totalDeduction = els.findTotalLoanByEmployee(employeeId) + withholding + rlip + phic + hdmf;
double netAmountPay = grossAmount - totalDeduction;
UI.getCurrent().access(() -> {
payroll.addRow(basicSalary,
0.0,
basicSalary,
PayrollConstants.PERA,
grossAmount,
withholding,
rlip,
phic,
hdmf,
totalDeduction,
netAmountPay,
netAmountPay/2,
netAmountPay/2);
});
}

class MyRunnable implements Runnable {

@Override
public void run() {
List<Employee> eList = es.findAllByPap(getDataId());
synchronized(eList){
for(Employee e : eList){
processPayroll(e.getEmployeeId());
UI.getCurrent().access(() -> {
if(current < dataSize){
status.setValue(""+(CommonUtil.roundOffToTwoDecimalPlaces((current/dataSize)*100))+"%");
current += 1;
progress.setValue(new Float(current/dataSize));
} else {
status.setValue("Finished... 100%");
}
});
}
}
}

};
Jet Beray
7 years ago Feb 12, 2016 2:47pm