Reputation:
I do use Runtime class
public void createDBStructure() throws IOException {
InputStream stream = DBStructureCreator.class.getClassLoader().getResourceAsStream("sql_structure");
if (stream == null) {
logger.log(Level.INFO, "File copy error: sql_structure is not found.");
} else {
String query;
query = StreamConverter.convertStreamToString(stream);
String cmd = "mysql -uroot -ppassw0rd";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
BufferedWriter buf = new BufferedWriter(new OutputStreamWriter(pr.getOutputStream()));
buf.write(query);
buf.write(";\n\n\n");
buf.write("exit\n\n\n");
buf.flush();
buf.close();
}
}
But it takes time to finish this task, still it does not block. And If I run some code imediately after tables may not be available yet. How to make it block until mysql is done creating tables. Either how to make it faster
Upvotes: 0
Views: 66
Reputation: 625
pr.waitfor() would wait until the process referenced by this Process instance completes.
Upvotes: 1