0

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

1 Answer 1

1

pr.waitfor() would wait until the process referenced by this Process instance completes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.