Skip to content

Commit

Permalink
rename Lealone.run(String[], Runnable) to Lealone.main(String[], Runn…
Browse files Browse the repository at this point in the history
…able)
  • Loading branch information
codefollower committed Dec 22, 2022
1 parent 2b38519 commit f6cbc6f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lealone-main/src/main/java/org/lealone/main/Lealone.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,11 @@ public static void main(String[] args) {
new Lealone().start(args);
}

public static void embed(String[] args) {
run(args, true, null);
}

// 外部调用者如果在独立的线程中启动Lealone,可以传递一个CountDownLatch等待Lealone启动就绪
public static void run(String[] args, boolean embedded, CountDownLatch latch) {
new Lealone().run(embedded, latch);
}

public static void run(String[] args, Runnable runnable) {
public static void main(String[] args, Runnable runnable) {
// 在一个新线程中启动 Lealone
CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> {
Lealone.run(args, false, latch);
new Lealone().start(args, latch);
}).start();
try {
latch.await();
Expand All @@ -66,6 +57,15 @@ public static void run(String[] args, Runnable runnable) {
}
}

public static void embed(String[] args) {
run(args, true, null);
}

// 外部调用者如果在独立的线程中启动Lealone,可以传递一个CountDownLatch等待Lealone启动就绪
public static void run(String[] args, boolean embedded, CountDownLatch latch) {
new Lealone().run(embedded, latch);
}

public static void runScript(String url, String... sqlScripts) {
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
Expand All @@ -84,6 +84,10 @@ public static void runScript(String url, String... sqlScripts) {
private String port;

public void start(String[] args) {
start(args, null);
}

public void start(String[] args, CountDownLatch latch) {
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i].trim();
if (arg.isEmpty())
Expand All @@ -106,7 +110,7 @@ public void start(String[] args) {
continue;
}
}
run(false, null);
run(false, latch);
}

private void showUsage() {
Expand Down

0 comments on commit f6cbc6f

Please sign in to comment.