Skip to content

Commit

Permalink
Refactor Symja#init
Browse files Browse the repository at this point in the history
  • Loading branch information
duy committed Oct 28, 2024
1 parent de151b2 commit fd4829d
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,42 @@ public class Symja {
private final ThreadGroup threadGroup = new ThreadGroup("CalculateThread");
private final ExprEvaluator exprEvaluator;

public Symja() {
init();
private Symja() {
this.exprEvaluator = new ExprEvaluator();
}

@WorkerThread
public static Symja getInstance() {
synchronized (lock) {
if (instance == null) {
initSymja();
instance = new Symja();
}
}
return instance;
}

@WorkerThread
public static void init() {
private static void initSymja() {
if (!systemInited.get()) {
try {
if (DLog.DEBUG) {
Log.d(TAG, "init called");
}
semaphore.acquire();

Config.DISPLAY_JSFIDDLE_BUTTON = false;
Config.JAVA_AWT_DESKTOP_AVAILABLE = false;

F.initSymbols();
ExprEvaluator exprEvaluator = new ExprEvaluator();
Log.d(TAG, String.valueOf(exprEvaluator.eval("Sin(x)+Cos(x)")));

systemInited.set(true);

if (DLog.DEBUG) {
Log.d(TAG, "init done");
}
} catch (Exception e) { // Should not throw error
e.printStackTrace();
Log.e(TAG, e.getMessage(), e);
} finally {
semaphore.release();
}
Expand Down

0 comments on commit fd4829d

Please sign in to comment.