JVM在试图声明已声明的打印机JavaPOS-EPSON热敏打印机时崩溃
我正在使用Epson_JavaPOS_ADK_11414_for_Linux_x64在PC上安装JavaPOS(JVM在试图声明已声明的打印机JavaPOS-EPSON热敏打印机时崩溃,java,thermal-printer,epson,javapos,Java,Thermal Printer,Epson,Javapos,我正在使用Epson_JavaPOS_ADK_11414_for_Linux_x64在PC上安装JavaPOS(sh installJavaPOSFull-64.sh) 我在不同的shell中一个接一个地运行此程序,第二个进程由于某种原因崩溃: import jpos.JposException; import jpos.POSPrinter; import jpos.util.JposPropertiesConst; import java.time.Duration; import jav
sh installJavaPOSFull-64.sh
)
我在不同的shell中一个接一个地运行此程序,第二个进程由于某种原因崩溃:
import jpos.JposException;
import jpos.POSPrinter;
import jpos.util.JposPropertiesConst;
import java.time.Duration;
import java.time.Instant;
public class POSPrinterClaimTest {
static POSPrinter posPrinter;
private static Boolean isOpen = false;
private static Boolean isClaimed = false;
private static Boolean isEnabled = false;
static {
System.setProperty(
JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "jpos.xml");
}
public static void main(String[] args) {
try {
posPrinter = new POSPrinter();
Instant start = Instant.now();
Instant finish = null;
Long timeElapsed = null;
openConnection("POSPrinter1");
finish = Instant.now();
timeElapsed = Duration.between(start, finish).toMillis();
System.out.println("Time taken to connect : " + timeElapsed.toString());
Thread.sleep(100000L);
terminate();
System.out.println("terminated from try block");
} catch (JposException | InterruptedException e) {
e.printStackTrace();
try {
terminate();
System.out.println("terminated from catch block");
Thread.sleep(5000);
} catch (JposException | InterruptedException jposException) {
jposException.printStackTrace();
}
} catch(Throwable t){
t.printStackTrace();
} finally {
posPrinter = null;
}
}
private static void openConnection(String printerName) throws JposException {
try {
String printerNamesss = printerName;
/**
* open the printer object according to the device logical name defined in jpos.xml
*/
posPrinter.open(printerName);
isOpen = true;
System.out.println("opened");
/**
* Get the exclusive control right for the opened device.
* Then the device is disable from other application.
* */
posPrinter.claim(3000);
isClaimed = true;
System.out.println("claimed");
/**
* enable the device for input and output
*/
posPrinter.setDeviceEnabled(true);
isEnabled = true;
System.out.println("enabled");
} catch (JposException jposException) {
System.out.println("jpos exception in open : " + jposException.getMessage());
throw jposException;
} catch(Throwable t) {
System.out.println("unknown throwable open: " + t.getMessage());
}
}
public static void terminate() throws JposException {
try {
if(isOpen && isClaimed) {
posPrinter.clearOutput();
System.out.println("cleared output");
}
if(isEnabled) {
posPrinter.setDeviceEnabled(false);
isEnabled = false;
System.out.println("setDeviceEnabled false");
}
if(isClaimed) {
posPrinter.release();
isClaimed = false;
System.out.println("released");
}
if(isOpen) {
posPrinter.close();
isOpen = false;
System.out.println("closed");
}
} catch (JposException jposException) {
jposException.printStackTrace();
throw jposException;
} catch(Throwable t) {
System.out.println("unknown throwable terminate: " + t.getMessage());
}
}
}
第一进程输出
opened
claimed
enabled
Time taken to connect : 7928 --> now I start the second process.
cleared output
setDeviceEnabled false
released
closed
terminated from try block
opened
jpos exception in open : The port is already open.
jpos.JposException: The port is already open.
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonUPOSExceptionCreator.createJposException(CommonUPOSExceptionCreator.java:138)
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonUPOSExceptionCreator.createJposException(CommonUPOSExceptionCreator.java:99)
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.openPort(CommonPrinterService.java:3341)
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.claim(CommonPrinterService.java:3103)
at jpos.BaseJposControl.claim(Unknown Source)
at POSPrinterClaimTestThreads.openConnection(POSPrinterClaimTestThreads.java:73)
at POSPrinterClaimTestThreads.test(POSPrinterClaimTestThreads.java:36)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
closed
terminated from catch block
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f43880ea9df, pid=12119, tid=0x00007f43690b0700
#
# JRE version: OpenJDK Runtime Environment (8.0_252-b09) (build 1.8.0_252-b09)
# Java VM: OpenJDK 64-Bit Server VM (25.252-b09 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libethernetio31.so+0x1f9df] CCommonPort::PortEvent(unsigned int, unsigned int, unsigned int*, unsigned int, unsigned char*)+0xf
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /POSPrinterTest/JavaPOS/hs_err_pid12119.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
Aborted
第二过程输出
opened
claimed
enabled
Time taken to connect : 7928 --> now I start the second process.
cleared output
setDeviceEnabled false
released
closed
terminated from try block
opened
jpos exception in open : The port is already open.
jpos.JposException: The port is already open.
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonUPOSExceptionCreator.createJposException(CommonUPOSExceptionCreator.java:138)
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonUPOSExceptionCreator.createJposException(CommonUPOSExceptionCreator.java:99)
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.openPort(CommonPrinterService.java:3341)
at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.claim(CommonPrinterService.java:3103)
at jpos.BaseJposControl.claim(Unknown Source)
at POSPrinterClaimTestThreads.openConnection(POSPrinterClaimTestThreads.java:73)
at POSPrinterClaimTestThreads.test(POSPrinterClaimTestThreads.java:36)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
closed
terminated from catch block
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f43880ea9df, pid=12119, tid=0x00007f43690b0700
#
# JRE version: OpenJDK Runtime Environment (8.0_252-b09) (build 1.8.0_252-b09)
# Java VM: OpenJDK 64-Bit Server VM (25.252-b09 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libethernetio31.so+0x1f9df] CCommonPort::PortEvent(unsigned int, unsigned int, unsigned int*, unsigned int, unsigned char*)+0xf
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /POSPrinterTest/JavaPOS/hs_err_pid12119.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
Aborted
如果您看到第二个进程抛出一个JposException,然后启动它的捕获并关闭连接。然后它突然崩溃,而不是沉睡5秒
有什么帮助吗?看来JavaPOS服务对象的独占控制处理工作不太好 您应该得到一个超时错误,而不是端口已打开的错误 但是,您的程序也很糟糕。
一次尝试、一次捕获的范围太广 JposException采用异常的形式,但实际上只是一个错误代码通知。
发出JposException信号并不意味着它会崩溃。
大多数情况下,如果您消除错误原因并重试,它将起作用。 为了正确起见,请尝试捕获每个方法调用和属性访问 Epson_JavaPOS_ADK示例程序应该是这样制作的。
请编写与示例程序相同的代码
此外: 你看到的不同吗?
对于每个方法和属性,它都会尝试以较小的单位进行捕获,并且不会使用throw将其传播到顶部。
我的一些资料来源是: 来自“Epson_JavaPOS_ADK_11414_for_Linux_x64\Sample\Samples\Printer\PrinterSample\u Step15\src\PrinterSample\u Step15\Step15Frame.java”
从评论和帖子中提取情况:
那么,索赔报告的错误可能是错误的,那么为什么不联系爱普生支持部门,提供有关这种情况的详细信息呢 从OP:
已经这么做了,但我们不知道他们是否会回应。所以,试着在这里找到答案;某处D 从OP: 我在一个进程中运行同一个程序,在两个脉冲中运行多个线程。我现在确实得到了你说的超时错误。只有在不同的过程场景中,我才会遇到崩溃 如果是这样,JavaPOS服务对象的进程间独占控制可能存在问题。这就是问题所在,但是崩溃可能是异常结束时的一个清理问题,正如我之前评论的那样。当Claim方法中发生异常时,请调用Close方法并尝试其他清理以正常结束,而不是通过传播异常来结束进程 从OP: 我在claim catch块中编写了posPrinter.close()。当使用两个进程和单线程时,它工作正常,崩溃频率显著降低。尽管如此,事故还是发生了一两次。但在两个进程中,每个进程都有10个线程试图声明打印机,结果导致一个进程能够声明,另一个进程崩溃<代码>尝试{posPrinter.claim(3000);}catch(JposException ex){posPrinter.close();}
似乎爱普生的JavaPOS服务对象的独占控制问题可能仍然存在。请根据这些调查信息向爱普生进行额外查询。在与爱普生团队讨论了这个问题后,他们能够为新的libepsonjpos.so和epsonjpos.jar提供解决方案 它为我解决了两个问题:
- 爱普生团队说要同步所有线程中的POSPrinter.open(),并用他们的补丁更新epsonjpos.jar
爱普生团队表示,他们将在下一个版本中发布补丁。很抱歉,程序不好,我只是想重新创建一个场景。我的spring应用程序正在使用这些库进行打印。出于某种原因,它在测试期间试图连接到声称的打印机时死机。如果我遵循控件,则在第二个进程中,该进程从声明中捕获JposException,并从主进程中的捕获关闭打印机。然后它崩溃了,出现了分段冲突。同样的行为也发生在我的spring应用程序中。虽然我捕获了所有“可见”异常,但应用程序一直在消亡。我正在跟踪ADK示例,此测试几乎与它们的实现类似。好吧,索赔报告的错误可能是错误的,那么,为什么不联系爱普生支持部门,提供有关这种情况的详细信息呢?已经这样做了,但我们不知道他们是否会回复。所以,试着在这里找到答案;某处关闭并退出一个可以重试的小错误不是很好吗?也许您没有在执行线程、事件处理程序、内存,或者在完成后必须清理的任何其他操作?