當我使用Java Bloomber V3 API它通常工作。但是,有時候,特別是在重新啓動後,bbcomm.exe沒有在後臺運行。我可以通過運行blp.exe手動啓動它,但我想知道是否有通過API這樣做的呢?在Java開始bbcomm V3彭博API
我仍然在等待幫助,幫助...
當我使用Java Bloomber V3 API它通常工作。但是,有時候,特別是在重新啓動後,bbcomm.exe沒有在後臺運行。我可以通過運行blp.exe手動啓動它,但我想知道是否有通過API這樣做的呢?在Java開始bbcomm V3彭博API
我仍然在等待幫助,幫助...
聊到服務檯後,事實證明,在64位Windows,64位JVM bbcomm下運行不會自動啓動。這在32位Java下不會發生 - 在32位bbcomm下自動運行。
所以我的解決方案,要麼等待問題彭博是固定的(現在我理解它),或檢查這種特殊情況下。
要檢查的具體情況:
os.arch
)java.vm.name
)bbcomm.exe
沒有運行。嘗試運行bbcomm.exe
使用Runtime.exec()
我還沒有測試過以上。它可能與Bloomberg對64位虛擬機的問題完全相同。
bbcomm.exe由V3 API自動啓動。
實際上,它有時是,但有時並非如此。我將在最終決議中添加一個答案 – 2009-12-17 12:47:42
您應該報告問題。 API客戶端庫 已經完全符合您所要做的。如果它不能連接到bbcomm,它會嘗試啓動它。如果這在某些情況下不起作用,如果您還沒有這樣做,您應該將它報告給彭博社。 – 2009-12-17 17:32:30
我已經完成了我在我的回答中提出的建議。我不會因爲經歷BB幫助臺的痛苦去找一個知道他們在說什麼的人而煩惱。如果你爲彭博社工作隨時舉報,或者私下給我發消息 – 2010-05-28 12:50:29
我們在使用.net API的Windows 7 64位機器上遇到同樣的問題。 bbcomm.exe不會自動啓動,唯一的解決方法是啓動「Bloomberg API DEMO」應用程序...
花費了一些時間與幫助幫助後,似乎bbcomm開始或者當您使用Excel API或運行API演示。但是,從Java API調用它時不會自動啓動。可能的方法來啓動它是:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
添加一個名爲bbcomm
與價值C:\blp\API\bbcomm.exe
一個字符串值 - 但打開這仍然可見一個命令行窗口,所以不一個真正的選擇(如果你關閉該窗口就終止bbcomm過程)START /MIN C:\blp\API\bbcomm.exe
和替換與(未測試)的註冊表項手動調用bbcomm默默private final static Logger logger = LoggerFactory.getLogger(BloombergUtils.class);
private final static String BBCOMM_PROCESS = "bbcomm.exe";
private final static String BBCOMM_FOLDER = "C:/blp/API";
/**
*
* @return true if the bbcomm process is running
*/
public static boolean isBloombergProcessRunning() {
return ShellUtils.isProcessRunning(BBCOMM_PROCESS);
}
/**
* Starts the bbcomm process, which is required to connect to the Bloomberg data feed
* @return true if bbcomm was started successfully, false otherwise
*/
public static boolean startBloombergProcessIfNecessary() {
if (isBloombergProcessRunning()) {
logger.info(BBCOMM_PROCESS + " is started");
return true;
}
Callable<Boolean> startBloombergProcess = getStartingCallable();
return getResultWithTimeout(startBloombergProcess, 1, TimeUnit.SECONDS);
}
private static Callable<Boolean> getStartingCallable() {
return new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
logger.info("Starting " + BBCOMM_PROCESS + " manually");
ProcessBuilder pb = new ProcessBuilder(BBCOMM_PROCESS);
pb.directory(new File(BBCOMM_FOLDER));
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.toLowerCase().contains("started")) {
logger.info(BBCOMM_PROCESS + " is started");
return true;
}
}
return false;
}
};
}
private static boolean getResultWithTimeout(Callable<Boolean> startBloombergProcess, int timeout, TimeUnit timeUnit) {
ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, "Bloomberg - bbcomm starter thread");
t.setDaemon(true);
return t;
}
});
Future<Boolean> future = executor.submit(startBloombergProcess);
try {
return future.get(timeout, timeUnit);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
return false;
} catch (ExecutionException | TimeoutException e) {
logger.error("Could not start bbcomm", e);
return false;
} finally {
executor.shutdownNow();
try {
if (!executor.awaitTermination(100, TimeUnit.MILLISECONDS)) {
logger.warn("bbcomm starter thread still running");
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
ShellUtils.java
public class ShellUtils {
private final static Logger logger = LoggerFactory.getLogger(ShellUtils.class);
/**
* @return a list of processes currently running
* @throws RuntimeException if the request sent to the OS to get the list of running processes fails
*/
public static List<String> getRunningProcesses() {
List<String> processes = new ArrayList<>();
try {
Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
int i = 0;
while ((line = input.readLine()) != null) {
if (!line.isEmpty()) {
String process = line.split(" ")[0];
if (process.contains("exe")) {
processes.add(process);
}
}
}
} catch (IOException e) {
throw new RuntimeException("Could not retrieve the list of running processes from the OS");
}
return processes;
}
/**
*
* @param processName the name of the process, for example "explorer.exe"
* @return true if the process is currently running
* @throws RuntimeException if the request sent to the OS to get the list of running processes fails
*/
public static boolean isProcessRunning(String processName) {
List<String> processes = getRunningProcesses();
return processes.contains(processName);
}
}
我已經試過了,並且它可以工作。 – 2010-05-28 12:49:28