Currently I am trying to develop JADE app that would have multiple agents, each of them connected to one common database. I know how to manage SQLite application and I don't have any problems with for example displaying table in one JADE agent.
The problem is:
I create 3 agents sharing the same SQLite database, let's call them A, B, C. I run them at once from another agent Z - this agent is only used to start agents A, B and C. Agents should end their work when selected or inserted data from database. Sometimes, for example, agent A did his work, B and C not. Another time agents A and C did their work and B not (it is like hang forever). I got different agents ended, but never all agents finished their work together.
The code is really simple and all agents are similar:
protected void setup()
{
Object args[] = getArguments();
if (args.length > 0) {
id = args[0].toString();
}
addBehaviour(new CyclicBehaviour(this)
{
@Override
public void action()
{
Statement stmt = null;
try {
stmt = connection.createStatement();
String sql = "DROP TABLE IF EXISTS TblTemp;";
stmt.executeUpdate(sql);
stmt.close();
stmt = connection.createStatement();
sql = "CREATE TABLE TblTemp" +
"(AdID INT PRIMARY KEY NOT NULL," +
" CategoryID INT NOT NULL, " +
" Title TEXT NOT NULL, " +
" IsContext INT);";
stmt.executeUpdate(sql);
stmt.close();
stmt = connection.createStatement();
sql = "INSERT INTO TblTemp SELECT AdID, CategoryID, Title, IsContext FROM TblWHERE CategoryID="+id+";";
stmt.executeUpdate(sql);
stmt.close();
doDelete();
} catch ( SQLException e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
block();
}
}
});
}
Never any exception is given.
What am I doing wrong?