管理对 Apache Derby 数据库的并发访问
我有一个 Apache Derby 数据库在 java swing 应用程序中运行(以网络模式),我通过 java 客户端应用程序通过直接 JDBC 调用连接到它。
这一切都非常好并且工作得很好,但是我知道需要为此客户端/服务器应用程序实现并发许可证。
理想情况下,拥有单用户许可证的用户应该能够在笔记本电脑上运行 1 个客户端应用程序,并在台式机上运行第二个客户端应用程序,并且能够从两者连接到服务器。
我没有奢侈的网络服务器,所以我想知道我唯一的选择是否是在 Derby 中使用“maxthreads”运行时属性,并从本质上强制用户必须注销笔记本电脑,如果他们想然后使用从他们的桌面应用程序。
如果我将 timeslice 属性保留为 0,那么对 getConnection 的调用将会超时,以便我可以向用户显示一条消息,解释他们需要断开其中一个客户端应用程序的连接。
连接线程是执行此操作的可靠方法吗?
我是否缺少另一个解决方案?
I have an Apache Derby database running (in networked mode) inside a java swing application, I connect to it through direct JDBC calls via a java client application.
This is all very good and works great however I know have an additional requirement to implement concurrent licenses for this client/server application.
Ideally a user with a single user license should be able to have 1 client app running on a laptop and also a second client app running on a desktop and be able to connect to the server from both.
I don't have the luxury of a web server so I am wondering if my only option is to use the "maxthreads" runtime property in Derby and essentially force the user to have to log off the laptop say if they want to then use the app from their desktop.
If I leave the timeslice property to 0 then will a call to getConnection timeout so that I can display a message to the user explaining that they need to disconnect one of the client apps.
Are connection threads a reliable way of doing this?
Am I missing another solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解了这个问题,那么您拥有用户锁定的许可证,并且希望阻止具有单个许可证的单个用户一次从多个客户端实例访问“服务器”。您的“服务器”只是一个数据库,您不想在服务器端创建应用程序层。
我真的不喜欢您最初的使用线程池和连接超时来强制许可限制的建议,因为这两个东西都用于其他目的。
相反,为了解决这个问题,我可能会考虑要求用户在第一次使用 GUI 时将其许可证号输入到 GUI 中。可以将其保存在用户的主目录中,以便后续启动 GUI。如果他们在另一台机器上第一次启动 GUI,也会发生同样的情况。然后,对于 GUI 与数据库进行的每个事务,它将首先更新许可证表或类似表以指示用户的许可证当前正在参与事务。只要表中已经存在相同的许可证,标记为活动的或类似的,GUI 就会拒绝交易并向用户显示他们的许可证已被另一个客户端使用。
如果你喜欢这个想法,请比我想得更深入。我可以看到一些逻辑错误将用户永久锁定:-)
If I understand the question correctly, you have user-locked licenses and want to prevent a single user with a single license from accessing the "server" from more than one instance of the client at a time. Your "server" is simply a database and you don't want to create an application layer on the server side.
I don't really like your initial suggestion of using the thread pool and connection timeout to enforce licensing constraints because both of those things are used for other purposes.
Instead, to solve this I might consider requiring the user to enter their license number into the GUI the first time they use it. This can be saved in the user's home directory for subsequent starts of the GUI. The same would happen if they start the GUI for the first time on another machine. Then, for each transaction the GUI makes with the database, it would first update a licenses table or similar to indicate the user's license is currently taking part in a transaction. Wherever the same license is already in the table, marked as active, or similar, the GUI would reject the transaction and display to the user their license is already in use by another client.
If you like this idea, think it through farther than I have. I can see some errors in logic locking users out permanently :-)
似乎您希望明确数据库的“登录”和“注销”操作,因此您可能希望在数据库中有一个特殊的表,您的应用程序在您登录或注销时在其中写入记录。
然后,您的应用程序可以查询该表以查明该应用程序的其他副本当前是否已登录。
您可能希望在表中包含其他字段来跟踪您登录/退出时的日期/时间、主机名和 IP 地址执行登录/注销等的客户端
It seems like you want to make the action of "logging in" and "logging out" of the database explicit, so perhaps you may want to have a special table in the database where your application writes a record when you log in or out.
Then your application can query that table to find out if other copies of the application are currently logged in.
You might want to include additional fields in the table to track the date/time when you logged in/out, the hostname and IP address of the client which performed the login/logout, etc.