1

我有两个 javafx 应用程序一个应用程序和更新程序。 App使用 Firebird 数据库来存储一些脆弱的用户数据。数据库以嵌入式模式运行(我认为这是相关的),这意味着同时只能有一个与数据库的连接(数据库创建一个锁定文件)。 更新程序更新应用程序。

整个架构如下所示:

  1. 用户运行 App-> App 正在检查是否需要更新,如果需要,它会启动 Updater(使用 java ProcessBuilder)并自行关闭(Platform.exit())。
  2. 更新程序检查应用程序是否已正确终止。
  3. 更新程序运行命令“App --export-user-data”(也使用 ProcessBuilder)在开始更新之前导出最重要的内容(必须以这种方式完成 - 我无法将此功能移动到更新程序)。
  4. 应用程序在第一个 session.beginTransaction() 冻结 - 没有单一错误或异常

到目前为止我所观察到的:

  • 当我启动 App 并按 [X] 将其关闭时,“C:\ProgramData\firebird”中的所有锁定文件都将被删除,但当 App 启动更新程序并自行关闭时,锁定文件将保持不变。我认为这就是 Hibernate 无法开始事务的原因。
  • 更新程序的进程不是 App 的子进程(我使用进程监视器检查了这个)
  • 当我直接启动 Updater 时,它就像一个魅力 - 所以问题只有在 App 启动 Updater 时才会出现。

我不能做的事情:

  • 将数据库切换到其他任何东西 - 它必须嵌入 firebird
  • 将导出功能移至更新程序

即使是最奇怪的想法我也会很感激,因为我花了四天时间试图解决这个问题。

编辑: 火鸟版本:2.1 Jaybird 版本:2.1.6

Updater 的启动方式(只有必要的东西)

public void startUpdater(){
    ProcessBuilder pb = new ProcessBuilder(updaterPath, argument)
    pb.start();
    Platform.exit();
}
4

1 回答 1

1

经过长时间的战斗,我终于有了解决方案。当java创建一个新进程时,子进程从它的父进程继承所有句柄。这就是为什么没有删除火鸟锁定文件的原因。我通过在 cpp 中创建小应用程序并在运行更新程序时将其用作代理解决了这个问题。

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

int _tmain( int argc, TCHAR *argv[] )
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    if( argc != 2 )
    {
        printf("Usage: %s [cmdline]\n", argv[0]);
        return 0;
    }

    // Start the child process. 
    if( !CreateProcess( NULL,   // No module name (use command line)
        argv[1],        // Command line
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        0,              // No creation flags
        NULL,           // Use parent's environment block
        NULL,           // Use parent's starting directory 
        &si,            // Pointer to STARTUPINFO structure
        &pi )           // Pointer to PROCESS_INFORMATION structure
    ) 
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );
        return 0;
    }

}
于 2016-11-24T12:05:10.213 回答