我試圖通過字符串從一個Java的Aplications參數,以秒爲啓動參數傳遞字符串從一個Java應用程序PARAMS另一個
例如我有必須調用啓動另一個Java Aplication Aplications(只包含只有JOptionPane,JDialog或簡單的JFrame)在System.exit(0);
之前,那裏我試圖從關閉應用程序發送一些描述到另一個,
這些代碼是模擬我試過,並在這種形式,代碼工作正常,並顯示字符串到JTextArea ...
import java.io.IOException;
import java.util.concurrent.*;
public class TestScheduler {
public static void main(String[] args) throws InterruptedException {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(true);
for (int i = 0; i < 10; i++) {
final int j = i;
System.out.println("assign : " + i);
ScheduledFuture<?> future = executor.schedule(new Runnable() {
@Override
public void run() {
System.out.println("run : " + j);
}
}, 2, TimeUnit.SECONDS);
}
System.out.println("executor.shutdown() ....");
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
try {
Process p = Runtime.getRuntime().exec("cmd /c start java -jar C:\\Dialog.jar 'Passed info'");
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("System.exit(0) .....");
System.exit(0);
}
private TestScheduler() {
}
}
//
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;
public class Main {
private static ArrayList<String> list = new ArrayList<String>();
public Main() {
JFrame frm = new JFrame();
JTextArea text = new JTextArea();
if (list.size() > 0) {
for (int i = 0; i < list.size(); ++i) {
text.append(list.get(i));
}
}
JScrollPane scroll = new JScrollPane(text,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.add(scroll, BorderLayout.CENTER);
frm.setLocation(150, 100);
frm.setSize(new Dimension(400, 300));
frm.setVisible(true);
}
public static void main(String[] args) {
if (args.length > 0) {
for (String s : args) {
list.add(s);
System.out.print(s + " ");
}
}
Main m = new Main();
}
}
我的問題:
EDIT1:如果是存在另一種方式如何從一個Java的Aplication傳遞一些值(必須有所謂的System.exit(0);)到另一個Java Aplication,另一種方式,因爲我試過通過使用Process /的ProcessBuilder
EDIT2:我crosspost http://forums.oracle.com/forums/thread.jspa?threadID=2229798&tstart=0
接受的答案從OTN
我認爲我不能問題與Proces或ProcessBuilder,這個例子正確地通過'通過信息',我會編輯我的話題 – mKorbel 2011-05-25 09:59:02