如何保留 Java 虚拟机 运行 并发送请求
How can I keep the Java Virtual Machine running and send requests
我是 Java 的初学者,我想向 planner 发送规划请求。
问题是执行时间很长,因为我每次都在启动 JVM
!
能否请您告诉我如何将 JVM
运行 作为服务器并发送请求而不是每次都启动 JVM
以减少执行时间?提前致谢。
我正在使用 python
像这样调用 JVM
:
def solver(
libraryPath='PDDL/pddl4j-devel/build/libs/pddl4j-3.8.3.jar',
planner = 'fr.uga.pddl4j.planners.htn.stn.tfd.TFDPlanner',
Memory = ['-Xms12288m' ,'-Xmx12288m'],
domainPath = 'new_domain.pddl',
problemPath = 'problem_main.pddl',
save=False
):
"""
Function: solver, to run the solver and get a plan if there is one.
---
Parameters:
@param: planner, string, planner name.
@param: libraryPath, string, the path to the java library(extension included)
@param: Memory, list of two ['-Xms size m', -Xmx size m'].
@param: domainPath, string, the path to the domain, (extension included).
@param: problemPath, string, the path to the problem, (extension included).
@param: save, boolean, to save the plan as log file.
---
@return: None.
"""
cmd = ['java', '-javaagent:'+libraryPath, '-server' , Memory[0] , Memory[1], planner, '-d', self.path+domainPath, '-p', self.path+problemPath]
result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
启动时间开销小于 50%。我知道这并不理想,但除非你对你的规划器进行相当多的优化,否则我不会那么担心。 ]
构建 long-running java 服务器应用程序是另一种选择,如前所述。有很多框架,例如 Spring.
对您来说,这可能有点矫枉过正,因此您可以查看一些有关构建“简单的 http 服务器”的教程,例如
- https://dzone.com/articles/simple-http-server-in-java
- https://www.youtube.com/watch?v=FNUdLeGfShU&list=PLAuGQNR28pW56GigraPdiI0oKwcs8gglW
或者使用套接字进一步降低级别:https://docs.oracle.com/javase/tutorial/networking/sockets/index.html
我是 Java 的初学者,我想向 planner 发送规划请求。
问题是执行时间很长,因为我每次都在启动 JVM
!
能否请您告诉我如何将 JVM
运行 作为服务器并发送请求而不是每次都启动 JVM
以减少执行时间?提前致谢。
我正在使用 python
像这样调用 JVM
:
def solver(
libraryPath='PDDL/pddl4j-devel/build/libs/pddl4j-3.8.3.jar',
planner = 'fr.uga.pddl4j.planners.htn.stn.tfd.TFDPlanner',
Memory = ['-Xms12288m' ,'-Xmx12288m'],
domainPath = 'new_domain.pddl',
problemPath = 'problem_main.pddl',
save=False
):
"""
Function: solver, to run the solver and get a plan if there is one.
---
Parameters:
@param: planner, string, planner name.
@param: libraryPath, string, the path to the java library(extension included)
@param: Memory, list of two ['-Xms size m', -Xmx size m'].
@param: domainPath, string, the path to the domain, (extension included).
@param: problemPath, string, the path to the problem, (extension included).
@param: save, boolean, to save the plan as log file.
---
@return: None.
"""
cmd = ['java', '-javaagent:'+libraryPath, '-server' , Memory[0] , Memory[1], planner, '-d', self.path+domainPath, '-p', self.path+problemPath]
result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
启动时间开销小于 50%。我知道这并不理想,但除非你对你的规划器进行相当多的优化,否则我不会那么担心。 ]
构建 long-running java 服务器应用程序是另一种选择,如前所述。有很多框架,例如 Spring.
对您来说,这可能有点矫枉过正,因此您可以查看一些有关构建“简单的 http 服务器”的教程,例如
- https://dzone.com/articles/simple-http-server-in-java
- https://www.youtube.com/watch?v=FNUdLeGfShU&list=PLAuGQNR28pW56GigraPdiI0oKwcs8gglW
或者使用套接字进一步降低级别:https://docs.oracle.com/javase/tutorial/networking/sockets/index.html