Example usage for java.lang Thread setUncaughtExceptionHandler

List of usage examples for java.lang Thread setUncaughtExceptionHandler

Introduction

In this page you can find the example usage for java.lang Thread setUncaughtExceptionHandler.

Prototype

public void setUncaughtExceptionHandler(UncaughtExceptionHandler eh) 

Source Link

Document

Set the handler invoked when this thread abruptly terminates due to an uncaught exception.

Usage

From source file:edu.brown.hstore.HStoreSite.java

/**
 * Initializes all the pieces that we need to start this HStore site up
 * This should only be called by our run() method
 *//*from  w  w w  .  j  av a2  s.  c  o m*/
protected HStoreSite init() {
    if (debug.val)
        LOG.debug("Initializing HStoreSite " + this.getSiteName());
    this.hstore_coordinator = this.initHStoreCoordinator();

    // First we need to tell the HStoreCoordinator to start-up and initialize its connections
    if (debug.val)
        LOG.debug("Starting HStoreCoordinator for " + this.getSiteName());
    this.hstore_coordinator.start();

    ThreadGroup auxGroup = this.threadManager.getThreadGroup(ThreadGroupType.AUXILIARY);

    // Start TransactionQueueManager
    Thread t = new Thread(auxGroup, this.txnQueueManager);
    t.setDaemon(true);
    t.setUncaughtExceptionHandler(this.exceptionHandler);
    t.start();

    // Start VoltNetwork
    t = new Thread(this.voltNetwork);
    t.setName(HStoreThreadManager.getThreadName(this, HStoreConstants.THREAD_NAME_VOLTNETWORK));
    t.setDaemon(true);
    t.setUncaughtExceptionHandler(this.exceptionHandler);
    t.start();

    // Start CommandLogWriter
    t = new Thread(auxGroup, this.commandLogger);
    t.setDaemon(true);
    t.setUncaughtExceptionHandler(this.exceptionHandler);
    t.start();

    // Start AntiCacheManager Queue Processor
    if (this.anticacheManager != null && this.anticacheManager.getEvictableTables().isEmpty() == false) {
        t = new Thread(auxGroup, this.anticacheManager);
        t.setDaemon(true);
        t.setUncaughtExceptionHandler(this.exceptionHandler);
        t.start();
    }

    // TransactionPreProcessors
    if (this.preProcessors != null) {
        for (TransactionPreProcessor tpp : this.preProcessors) {
            t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.PROCESSING), tpp);
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(this.exceptionHandler);
            t.start();
        } // FOR
    }
    // TransactionPostProcessors
    if (this.postProcessors != null) {
        for (TransactionPostProcessor tpp : this.postProcessors) {
            t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.PROCESSING), tpp);
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(this.exceptionHandler);
            t.start();
        } // FOR
    }

    // Then we need to start all of the PartitionExecutor in threads
    if (debug.val)
        LOG.debug(String.format("Starting PartitionExecutor threads for %s partitions on %s",
                this.local_partitions.size(), this.getSiteName()));
    for (int partition : this.local_partitions.values()) {
        PartitionExecutor executor = this.getPartitionExecutor(partition);
        // executor.initHStoreSite(this);

        t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.EXECUTION), executor);
        t.setDaemon(true);
        t.setPriority(Thread.MAX_PRIORITY); // Probably does nothing...
        t.setUncaughtExceptionHandler(this.exceptionHandler);
        this.executor_threads[partition] = t;
        t.start();
    } // FOR

    // Start Transaction Cleaners
    int i = 0;
    for (TransactionCleaner cleaner : this.txnCleaners) {
        String name = String.format("%s-%02d",
                HStoreThreadManager.getThreadName(this, HStoreConstants.THREAD_NAME_TXNCLEANER), i);
        t = new Thread(this.threadManager.getThreadGroup(ThreadGroupType.CLEANER), cleaner);
        t.setName(name);
        t.setDaemon(true);
        t.setUncaughtExceptionHandler(this.exceptionHandler);
        t.start();
        i += 1;
    } // FOR

    this.initPeriodicWorks();

    // Transaction Profile CSV Dumper
    if (hstore_conf.site.txn_profiling && hstore_conf.site.txn_profiling_dump) {
        File csvFile = new File(hstore_conf.global.log_dir + File.separator + this.getSiteName().toLowerCase()
                + "-profiler.csv");
        this.txn_profiler_dumper = new TransactionProfilerDumper(csvFile);
        LOG.info(String.format("Transaction profile data will be written to '%s'", csvFile));
    }

    // Add in our shutdown hook
    // Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook()));

    return (this);
}

From source file:com.kdmanalytics.toif.assimilator.Assimilator.java

private void processKdmXmlFile(final List<File> kdmFiles)
        throws FileNotFoundException, IOException, RepositoryException, ToifException {
    if (debug) {//from  w  w  w . j a v  a  2  s  . c  o m
        LOG.debug("processing kdm file...");
        //System.err.println("processing kdm file...");
    }

    PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    final ThreadStatus status = new ThreadStatus();

    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            KdmXmlHandler handler = null;
            try {
                if (kdmFiles.size() > 1) {
                    final String msg = "There should only be one .kdm file.";
                    LOG.error(msg);
                    throw new ToifException(msg);
                } else if (kdmFiles.size() == 1) {
                    File kdmFile = kdmFiles.get(0); // get the head of
                                                    // thelist.
                    handler = load(kdmFile, out);
                }
                out.flush();
                out.close();

                if (handler == null) {
                    return;
                }
                setNextId(handler.getNextId());
                setSmallestBigNumber(handler.getSmallestBigNumber());
                // increase
            } catch (IOException e) {
                final String msg = "IO exception whilst processing kdm file. "
                        + ". Possibly an existing kdm file is in your input path!";

                LOG.error(msg, e);
                status.exception = new ToifException(msg, e);
            } catch (RepositoryException e) {
                final String msg = "Repository Exception whilst processing kdm file. "
                        + ". Possibly an existing kdm file is in your input path!";

                LOG.error(msg, e);
                status.exception = new ToifException(msg, e);
            } catch (ToifException e) {
                // RJF final String msg =
                // "Processing Exception whilst processing kdm file. "
                // + ". Possibly that input file is invalid XML!";

                // LOG.error(msg, e);
                status.exception = e;
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException e) {
                        // Just leave it alone
                        LOG.error("unable to close stream");
                    }
            }
        }
    });

    // ---------------------------------------------------------
    // Unable to change logic within the short time frame given so
    // adding a means to catch unknown exceptions in thread
    // ----------------------------------------------------------
    Thread.UncaughtExceptionHandler tueh = new Thread.UncaughtExceptionHandler() {

        public void uncaughtException(Thread th, Throwable ex) {
            LOG.error("Uncaught exception: " + ex);
            status.exception = (Exception) ex;
        }
    };

    t.setUncaughtExceptionHandler(tueh);
    t.start();

    streamStatementsToRepo(in);
    try {
        t.join();

        // Check if we enoutered exception during processing and
        // proxy throw if we have one
        if (status.exception != null) {
            // Leave alone if already a ToifException
            if (status.exception instanceof ToifException)
                throw (ToifException) status.exception;
            else
                throw new ToifException(status.exception);

        }
    } catch (InterruptedException e) {
        LOG.error("Interrupted");
        throw new ToifException("Interrupted");
    }
}

From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java

@Test
@DisplayName("Cross-Browser test")
void crossBrowserTest() throws Exception {

    setupBrowser("chrome");

    log.info("Cross-Browser test");

    Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread th, Throwable ex) {
            System.out.println("Uncaught exception: " + ex);
            synchronized (lock) {
                OpenViduTestAppE2eTest.ex = new Exception(ex);
            }/* ww  w  . j  av  a  2 s  .  c  om*/
        }
    };

    Thread t = new Thread(() -> {
        MyUser user2 = new MyUser(new FirefoxUser("TestUser", 30));
        otherUsers.add(user2);
        user2.getDriver().get(APP_URL);
        WebElement urlInput = user2.getDriver().findElement(By.id("openvidu-url"));
        urlInput.clear();
        urlInput.sendKeys(OPENVIDU_URL);
        WebElement secretInput = user2.getDriver().findElement(By.id("openvidu-secret"));
        secretInput.clear();
        secretInput.sendKeys(OPENVIDU_SECRET);

        user2.getEventManager().startPolling();

        user2.getDriver().findElement(By.id("add-user-btn")).click();
        user2.getDriver().findElement(By.className("join-btn")).click();
        try {
            user2.getEventManager().waitUntilEventReaches("connectionCreated", 2);
            user2.getEventManager().waitUntilEventReaches("accessAllowed", 1);
            user2.getEventManager().waitUntilEventReaches("streamCreated", 2);
            user2.getEventManager().waitUntilEventReaches("streamPlaying", 2);

            final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
            Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos);
            Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager()
                    .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true));

            user2.getEventManager().waitUntilEventReaches("streamDestroyed", 1);
            user2.getEventManager().waitUntilEventReaches("connectionDestroyed", 1);
            user2.getDriver().findElement(By.id("remove-user-btn")).click();
            user2.getEventManager().waitUntilEventReaches("sessionDisconnected", 1);
        } catch (Exception e) {
            e.printStackTrace();
            user2.dispose();
            Thread.currentThread().interrupt();
        }
        user2.dispose();
    });
    t.setUncaughtExceptionHandler(h);
    t.start();

    user.getDriver().findElement(By.id("add-user-btn")).click();
    user.getDriver().findElement(By.className("join-btn")).click();

    user.getEventManager().waitUntilEventReaches("connectionCreated", 2);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 1);
    user.getEventManager().waitUntilEventReaches("streamCreated", 2);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 2);

    final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
    Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos);
    Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager()
            .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true));

    gracefullyLeaveParticipants(1);

    t.join();

    synchronized (lock) {
        if (OpenViduTestAppE2eTest.ex != null) {
            throw OpenViduTestAppE2eTest.ex;
        }
    }
}

From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java

@Test
@DisplayName("Remote record cross-browser audio-only and video-only")
void remoteRecordAudioOnlyVideoOnlyTest() throws Exception {
    isRecordingTest = true;//from w  w  w.  j  ava  2s . c o m

    setupBrowser("chromeAlternateScreenShare");

    log.info("Remote record cross-browser audio-only and video-only");

    final String SESSION_NAME = "TestSession";
    final String RECORDING_COMPOSED_VIDEO = "COMPOSED_VIDEO_ONLY";
    final String RECORDING_COMPOSED_AUDIO = "COMPOSED_AUDIO_ONLY";
    final String RECORDING_INDIVIDUAL_VIDEO = "INDIVIDUAL_VIDEO_ONLY";
    final String RECORDING_INDIVIDUAL_AUDIO = "INDIVIDUAL_AUDIO_ONLY";
    final int RECORDING_DURATION = 5000;

    Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread th, Throwable ex) {
            System.out.println("Uncaught exception: " + ex);
            synchronized (lock) {
                OpenViduTestAppE2eTest.ex = new Exception(ex);
            }
        }
    };

    Thread t = new Thread(() -> {
        MyUser user2 = new MyUser(new FirefoxUser("FirefoxUser", 30));
        otherUsers.add(user2);
        user2.getDriver().get(APP_URL);
        WebElement urlInput = user2.getDriver().findElement(By.id("openvidu-url"));
        urlInput.clear();
        urlInput.sendKeys(OPENVIDU_URL);
        WebElement secretInput = user2.getDriver().findElement(By.id("openvidu-secret"));
        secretInput.clear();
        secretInput.sendKeys(OPENVIDU_SECRET);

        user2.getEventManager().startPolling();

        // Firefox user audio + video
        user2.getDriver().findElement(By.id("add-user-btn")).click();

        // Firefox user video-only
        user2.getDriver().findElement(By.id("add-user-btn")).click();
        user2.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .send-audio-checkbox")).click();

        // Join Firefox users
        user2.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER));

        try {
            user2.getEventManager().waitUntilEventReaches("connectionCreated", 4);
            user2.getEventManager().waitUntilEventReaches("accessAllowed", 2);
            user2.getEventManager().waitUntilEventReaches("streamCreated", 8);
            user2.getEventManager().waitUntilEventReaches("streamPlaying", 8);

            int nVideos = user2.getDriver().findElements(By.tagName("video")).size();
            Assert.assertEquals("Expected 8 videos in Firefox user but found " + nVideos, 8, nVideos);

            user2.getEventManager().waitUntilEventReaches("recordingStarted", 2);
            user2.getEventManager().waitUntilEventReaches("recordingStopped", 2);

            user2.getEventManager().waitUntilEventReaches("recordingStarted", 4);
            user2.getEventManager().waitUntilEventReaches("recordingStopped", 4);

            user2.getEventManager().waitUntilEventReaches("recordingStarted", 6);
            user2.getEventManager().waitUntilEventReaches("recordingStopped", 6);

            user2.getEventManager().waitUntilEventReaches("recordingStarted", 8);
            user2.getEventManager().waitUntilEventReaches("recordingStopped", 8);

            user2.getEventManager().waitUntilEventReaches("streamDestroyed", 4);
            user2.getEventManager().waitUntilEventReaches("connectionDestroyed", 4);
            user2.getDriver().findElement(By.id("remove-user-btn")).click();
            user2.getDriver().findElement(By.id("remove-user-btn")).click();
            user2.getEventManager().waitUntilEventReaches("sessionDisconnected", 2);
        } catch (Exception e) {
            e.printStackTrace();
            user2.dispose();
            Thread.currentThread().interrupt();
        }
        user2.dispose();
    });
    t.setUncaughtExceptionHandler(h);
    t.start();

    // Chrome user screen share only-video
    user.getDriver().findElement(By.id("add-user-btn")).click();
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .screen-radio")).click();
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .send-audio-checkbox")).click();

    // Chrome user audio-only
    user.getDriver().findElement(By.id("add-user-btn")).click();
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .send-video-checkbox")).click();

    // Join Chrome users
    user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER));

    user.getEventManager().waitUntilEventReaches("connectionCreated", 4);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 2);
    user.getEventManager().waitUntilEventReaches("streamCreated", 8);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 8);

    int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
    Assert.assertEquals("Expected 8 videos but found " + numberOfVideos, 8, numberOfVideos);

    user.getDriver().findElement(By.id("session-api-btn-0")).click();
    Thread.sleep(1000);
    user.getDriver().findElement(By.id("rec-properties-btn")).click();
    Thread.sleep(500);

    WebElement recordingNameField = user.getDriver().findElement(By.id("recording-name-field"));

    // Video-only COMPOSED recording
    recordingNameField.clear();
    recordingNameField.sendKeys(RECORDING_COMPOSED_VIDEO);
    user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click();
    Thread.sleep(500);
    user.getDriver().findElement(By.id("start-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording started [" + SESSION_NAME + "]"));
    user.getEventManager().waitUntilEventReaches("recordingStarted", 2);

    Thread.sleep(RECORDING_DURATION);

    user.getDriver().findElement(By.id("recording-id-field")).clear();
    user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME);
    user.getDriver().findElement(By.id("stop-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording stopped [" + SESSION_NAME + "]"));
    user.getEventManager().waitUntilEventReaches("recordingStopped", 2);

    // Audio-only COMPOSED recording
    recordingNameField.clear();
    recordingNameField.sendKeys(RECORDING_COMPOSED_AUDIO);
    user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click();
    user.getDriver().findElement(By.id("rec-hasvideo-checkbox")).click();
    Thread.sleep(500);
    user.getDriver().findElement(By.id("start-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording started [" + SESSION_NAME + "-1]"));
    user.getEventManager().waitUntilEventReaches("recordingStarted", 4);

    Thread.sleep(RECORDING_DURATION);

    user.getDriver().findElement(By.id("recording-id-field")).clear();
    user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME + "-1");
    user.getDriver().findElement(By.id("stop-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording stopped [" + SESSION_NAME + "-1]"));
    user.getEventManager().waitUntilEventReaches("recordingStopped", 4);

    // Video-only INDIVIDUAL recording
    recordingNameField.clear();
    recordingNameField.sendKeys(RECORDING_INDIVIDUAL_VIDEO);
    user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click();
    user.getDriver().findElement(By.id("rec-hasvideo-checkbox")).click();
    Thread.sleep(500);
    user.getDriver().findElement(By.id("rec-outputmode-select")).click();
    Thread.sleep(500);
    user.getDriver().findElement(By.id("option-INDIVIDUAL")).click();
    Thread.sleep(500);
    user.getDriver().findElement(By.id("start-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording started [" + SESSION_NAME + "-2]"));
    user.getEventManager().waitUntilEventReaches("recordingStarted", 6);

    Thread.sleep(RECORDING_DURATION);

    user.getDriver().findElement(By.id("recording-id-field")).clear();
    user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME + "-2");
    user.getDriver().findElement(By.id("stop-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording stopped [" + SESSION_NAME + "-2]"));
    user.getEventManager().waitUntilEventReaches("recordingStopped", 6);

    // Audio-only INDIVIDUAL recording
    recordingNameField.clear();
    recordingNameField.sendKeys(RECORDING_INDIVIDUAL_AUDIO);
    user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click();
    user.getDriver().findElement(By.id("rec-hasvideo-checkbox")).click();
    Thread.sleep(500);
    user.getDriver().findElement(By.id("start-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording started [" + SESSION_NAME + "-3]"));
    user.getEventManager().waitUntilEventReaches("recordingStarted", 8);

    Thread.sleep(RECORDING_DURATION);

    user.getDriver().findElement(By.id("recording-id-field")).clear();
    user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME + "-3");
    user.getDriver().findElement(By.id("stop-recording-btn")).click();
    user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
            "Recording stopped [" + SESSION_NAME + "-3]"));
    user.getEventManager().waitUntilEventReaches("recordingStopped", 8);

    String recordingsPath = "/opt/openvidu/recordings/";

    // Check video-only COMPOSED recording
    String recPath = recordingsPath + SESSION_NAME + "/";
    Recording recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME);
    this.checkMultimediaFile(new File(recPath + recording.getName() + ".mp4"), false, true,
            recording.getDuration(), recording.getResolution(), null, "h264", true);

    // Check audio-only COMPOSED recording
    recPath = recordingsPath + SESSION_NAME + "-1/";
    recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME + "-1");
    this.checkMultimediaFile(new File(recPath + recording.getName() + ".webm"), true, false,
            recording.getDuration(), null, "opus", null, true);

    // Check video-only INDIVIDUAL recording
    recPath = recordingsPath + SESSION_NAME + "-2/";
    recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME + "-2");
    this.checkIndividualRecording(recPath, recording, 3, "opus", "vp8", true);

    // Check audio-only INDIVIDUAL recording
    recPath = recordingsPath + SESSION_NAME + "-3/";
    recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME + "-3");
    this.checkIndividualRecording(recPath, recording, 2, "opus", "vp8", true);

    user.getDriver().findElement(By.id("close-dialog-btn")).click();
    Thread.sleep(500);

    gracefullyLeaveParticipants(2);

    t.join();

    synchronized (lock) {
        if (OpenViduTestAppE2eTest.ex != null) {
            throw OpenViduTestAppE2eTest.ex;
        }
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

private String getUserAgent() {
    try {/*from  ww w  .  j a  va  2s .  c  om*/
        String userAgent = System.getProperty("http.agent");
        if (userAgent != null) {
            return userAgent;
        }
    } catch (Exception e) {
    }
    if (getActivity() == null) {
        return "Android-CN1";
    }
    try {
        Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class,
                WebView.class);
        constructor.setAccessible(true);
        try {
            WebSettings settings = constructor.newInstance(getActivity(), null);
            return settings.getUserAgentString();
        } finally {
            constructor.setAccessible(false);
        }
    } catch (Exception e) {
        final StringBuffer ua = new StringBuffer();
        if (Thread.currentThread().getName().equalsIgnoreCase("main")) {
            WebView m_webview = new WebView(getActivity());
            ua.append(m_webview.getSettings().getUserAgentString());
            m_webview.destroy();
        } else {
            final boolean[] flag = new boolean[1];
            Thread thread = new Thread() {
                public void run() {
                    Looper.prepare();
                    WebView m_webview = new WebView(getActivity());
                    ua.append(m_webview.getSettings().getUserAgentString());
                    m_webview.destroy();
                    Looper.loop();
                    flag[0] = true;
                    synchronized (flag) {
                        flag.notify();
                    }
                }
            };
            thread.setUncaughtExceptionHandler(AndroidImplementation.exceptionHandler);
            thread.start();
            while (!flag[0]) {
                synchronized (flag) {
                    try {
                        flag.wait(100);
                    } catch (InterruptedException ex) {
                    }
                }
            }
        }
        return ua.toString();
    }
}