使用多线程在Flex和Java中登录

utugiqy6  于 2022-09-21  发布在  Java
关注(0)|答案(1)|浏览(118)

我在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 fingern");
            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;
}
zrfyljdw

zrfyljdw1#

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

相关问题