Hi..
I'm writed some code for my custom code service using java but in console it doesnt allowed to upload it , its said can not use java class(java.lang) !
the code is pretty simple it just wait until an operation finished for example calling External Api to get data and return result or using App42 Service (UserService, SessionService, etc..)
please let me know how can solve this problem or another solution for doing this job
example of code i using
private synchronized String getData() {
res = "nonvalue";
SessionService session = sp.buildSessionManager();
Message message = new Message();
message.response = "nonvalue";
Waiter waiter = new Waiter(message);
Thread waiterThread = new Thread(waiter, "waiterThread");
waiterThread.start();
Notifier notifier = new Notifier(message, sp);
Thread notifierThread = new Thread(notifier, "notifierThread");
notifierThread.start();
return message.response;
}
private class Message{
String response;
}
private class Waiter implements Runnable {
private Message message;
public Waiter(Message message) {
this.message = message;
}
@Override
public void run() {
synchronized (message) {
try {
//System.out.println("waiting for the notifier at");
message.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private class Notifier implements Runnable {
Message message;
ServiceAPI sp;
public Notifier(Message message, ServiceAPI sp) {
this.message = message;
this.sp = sp;
}
@Override
public void run() {
SessionService session = sp.buildSessionManager();
session.getSession("rebaz", false, new App42CallBack() {
@Override
public void onSuccess(Object response) {
Session session = (Session)response;
//System.out.println("already logged" + session.getSessionId());
finishJob ("already logged");
}
@Override
public void onException(Exception e) {
// TODO Auto-generated method stub
//System.out.println("not logged" + e.getMessage());
finishJob( "not logged" + e.getMessage());
}
});
}
private void finishJob(String response) {
synchronized (message) {
message.response = response;
message.notify();
}
}
}
I Can use while loop and get the same result but i dont think it good
Thanks