thanks for all the help, i implemented your method with the executor, and im still getting the illegalStateException error, but only when i try to save, when it reads the values it reads them in fine and correctly
Code:
public class ModelTrainerExecutor {
public class ModelTrainer implements Runnable {
private int modelUID;
private SessionFactory sessionFact;
public ModelTrainer(Model m, SessionFactory sf)
{
modelUID=m.getUID();
sessionFact=sf;
}
public ModelTrainer(int m, SessionFactory sf)
{
modelUID=m;
sessionFact=sf;
}
public void run()
{
Session session = sessionFact.openSession();
Model mod=(Model)session.load(Model.class, modelUID);
mod.setSchedueled(false);
System.out.println(mod.getName().trim()+" is now training");
Blob file = mod.getFile();
if(file==null)
file=new Blob();
String code = "";
String reg = "";
String div="";
int i=0;
for(Tag t : mod.getTrainingSet().getCodeBook().getTags())
{
if(i<4)
{
String subReg=t.getCode().trim();
String subCode = t.getName().trim();
if (i == 0)
div="";
else
div="<>";
code += div+subCode;
reg += div+subReg;
}
i++;
}
code = code.replace("\\s+", "");
MEDClassifier medc = new MEDClassifier();
String[] codes = code.split("<>");
String[] regs = reg.toLowerCase().split("<>");
file.setData(medc.train(mod.getTrainingSet(), codes, regs));
file.setFileName(mod.getName());
file.setContentType("application/PDt");
mod.setTrained(true);
mod.setSchedueled(false);
session.saveOrUpdate(file);
mod.setFile(file);
session.saveOrUpdate(mod);
}
}
private TaskExecutor taskExecutor;
public ModelTrainerExecutor(TaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
}
public void train(int uid,SessionFactory sf) {
for(int i = 0; i < 25; i++) {
taskExecutor.execute(new ModelTrainer(uid,sf));
}
}
}
here is the code that calls it
Code:
TimerTaskExecutor tte = new TimerTaskExecutor();
tte.setDelay(10*1000);
tte.afterPropertiesSet();
(new ModelTrainerExecutor(tte)).train(mod.getUID(),taggerDAO.getSessionFactory());
im basicaly getting the same problem i was before, when it tries to update, it just does nothing, and when i tries to save, it errors out
thanks for you help