1

我在 java 和 flex 中的登录应用程序有问题。我们使用指纹登录。系统等待用户输入任何指纹 60 秒。之后它会自动退出页面。用户在该页面上还有文本密码选项。当用户单击该选项时,控制转到其他页面。但问题是,当用户单击文本密码选项时,他会被重定向,但 60 秒的线程会继续运行。任何人都可以帮助我如何停止该线程。这是我的代码。我正在使用阻塞队列概念通过输入一些虚拟值来退出输入屏幕。

private void interruptCaptureProcess() {
    System.out.println("Interrupting Capture Process.");
    ExactScheduledRunnable fingerScanInterruptThread = new ExactScheduledRunnable()
    {
        public void run()
        {
            try
            {
                if (capture != null) 
                {
                    DPFPSampleFactoryImpl test = new DPFPSampleFactoryImpl();
                    samples.put(test.createSample(new byte[1]));
                    capture.stopCapture();
                }
            }
            catch (Exception e) 
            {
                LOGGER.error("interruptCaptureProcess", e);
                e.printStackTrace();
            }
        }
    };
    timeOutScheduler.schedule(fingerScanInterruptThread, getTimeOutValue(), TimeUnit.SECONDS);
}

/**
 * Scans and Verifies the user finger print by matching it with the previous registered template for the user.
 * 
 * @param userVO is the user value object which has to be verified.
 * @return the acknowledgment string according to result for operation performed.
 * @throws UserServiceException when there is an error in case of getting user record.
 */
public String verifyUserFingerPrint(Long userId) throws LoginServiceException {
    System.out.println("Performing fingerprint verification...\n");
    interruptCaptureProcess();
    UserVO userVO = null;
    try {

        userVO = new UserService().findUserById(userId, true);
        if (userVO != null) {

            stopCaptureProcess();
            DPFPSample sample = getSample(selectReader(), "Scan your finger\n");
            timeOutScheduler.shutdownNow();
            if (sample.serialize().length == 1) {
                System.out.println("Coming in code");
                return null;
            } else if (sample.serialize().length == 2) {
                System.out.println("Capturing Process has been Timed-Out");
                return TIMEOUT;
            }

            if (sample == null)
                throw new UserServiceException("Error in scanning finger");

            DPFPFeatureExtraction featureExtractor = DPFPGlobal.getFeatureExtractionFactory()
                .createFeatureExtraction();
            DPFPFeatureSet featureSet = featureExtractor.createFeatureSet(sample,
                DPFPDataPurpose.DATA_PURPOSE_VERIFICATION);
            DPFPVerification matcher = DPFPGlobal.getVerificationFactory().createVerification();
            matcher.setFARRequested(DPFPVerification.MEDIUM_SECURITY_FAR);

            byte[] tempByte = userVO.getFingerPrint();
            DPFPTemplateFactory facotory = new DPFPTemplateFactoryImpl();
            for (DPFPFingerIndex finger : DPFPFingerIndex.values()) {
                DPFPTemplate template = facotory.createTemplate(tempByte);
                if (template != null) {
                    DPFPVerificationResult result = matcher.verify(featureSet, template);
                    // Fix of enh#1029
                    Map<ScriptRxConfigType, Map<ScriptRxConfigName, String>> scriptRxConfigMap = ScriptRxConfigMapSingleton
                        .getInstance().getScriptRxConfigMap();
                    Map<ScriptRxConfigName, String> fingerPrintPropertiesMap = scriptRxConfigMap
                        .get(ScriptRxConfigType.FINGERPRINT);
                    String fingerPrintDemoMode = fingerPrintPropertiesMap.get(ScriptRxConfigName.DEMOMODE);
                    if (fingerPrintDemoMode != null && fingerPrintDemoMode.equalsIgnoreCase("DemoEnabled")) {
                        return "LOGS_MSG_101";
                    }
                    // End of fix of enh#1029
                    if (result.isVerified()) {
                        System.out.println("Matching finger: %s, FAR achieved: %g.\n" + fingerName(finger)
                            + (double) result.getFalseAcceptRate() / DPFPVerification.PROBABILITY_ONE);
                        return "LOGS_MSG_101";
                    }
                }
            }
        }
    } catch (IndexOutOfBoundsException iob) {
        LOGGER.error("verifyUserFingerPrint", iob);
        throw new LoginServiceException("LOGS_ERR_101", iob);
    } catch (Exception exp) {
        LOGGER.error("verifyUserFingerPrint", exp);
        System.out.println("Failed to perform verification.");
        throw new LoginServiceException("LOGS_ERR_105", exp);
    } catch (Throwable th) {
        LOGGER.error("verifyUserFingerPrint", th);
        throw new LoginServiceException("LOGS_ERR_106", th.getMessage(), th);
    }
    System.out.println("No matching fingers found for \"%s\".\n" + userVO.getFirstName().toUpperCase());
    throw new LoginServiceException("LOGS_ERR_107", null);
}


/* finger scanning process
 */
private void stopCaptureProcess() {
    ExactScheduledRunnable fingerScanInterruptThread = new ExactScheduledRunnable() {
        public void run() {
            try {
                DPFPSampleFactoryImpl test = new DPFPSampleFactoryImpl();
                samples.put(test.createSample(new byte[2]));
                capture.stopCapture();
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }
    };
    timeOutScheduler.schedule(fingerScanInterruptThread, getTimeOutValue(), TimeUnit.SECONDS);
}

/**
 * API will get the value for the finger scanner time out configuration(Default will be 60 seconds)
 */
private long getTimeOutValue() {
    long waitTime = 60;
    String configValue = ScriptRxSingleton.getInstance().getConfigurationValue(ConfigType.Security,
        ConfigName.FingerprintTimeout);
    try {
        waitTime = Long.valueOf(configValue);
    } catch (NumberFormatException e) {
        LOGGER.debug("Configuration value is not a number for FingerTimeOut", e);
    }
    return waitTime;
}
4

1 回答 1

0

在 Java 中停止阻塞任务是一个复杂的话题,需要阻塞代码和想要解除阻塞的代码之间的合作。Java 中最常见的方法是中断阻塞的线程,如果阻塞的代码和它周围的代码理解中断,这种方法就可以工作。如果不是这种情况,你就不走运了。这是一个答案,它解释了一种中断阻塞线程的方法Executorhttps ://stackoverflow.com/a/9281038/1109

于 2020-03-24T08:24:47.257 回答