Skip to content Skip to sidebar Skip to footer

Whole Java Application Becomes Unresponsive After C Function Call From Java Thread

I have defined this kind of Android Java class, where native function baresipStart() never terminates: package com.tutpro.baresip; public class BaresipThread extends Thread {

Solution 1:

Thread.start() is responsible for actually creating the new thread of execution and setting it running. By overriding it as you did, you cause it to instead run baresipStart(), in the thread that invokes start().

Instead of overriding start(), you should override run(). This method is what defines the work to be performed in the new thread of execution.

Furthermore, if native method baresipStart() indeed never returns then you have a problem. Your application cannot terminate while it has any active threads. Supposing that you intend for baresipStop() to cause the thread to finish, you should arrange for baresipStart() to return (or to throw an unchecked exception) when execution is terminated by an invocation of baresipStop(). Do be aware, however, that those native methods need to be thread-safe, because they will, perforce, be invoked by different Java threads.

Solution 2:

Thanks for your explanation. I got the new baresip thread started by removing BaresipThread object altogether and replacing the three lines above with this:

new Thread(new Runnable() {
    public void run() {
        baresipStart();
    }
}).start();

User can stop the resulting process via its user interface after which the application is terminated.

Post a Comment for "Whole Java Application Becomes Unresponsive After C Function Call From Java Thread"