开始:我是开源软件的新手。(Apache-Tomcat / Java / Restletframework)
这是我的问题:我正在使用 Restlet 框架构建一个应用程序。我不知道我的编码/方法是否是线程安全的!?有人可以告诉我我是否以正确的方式编码吗?还是我无可救药地失败了?
构造:
- CLASS A 将由客户端调用。(REST 请求)
- CLASS A(路由器)将调用 CLASS B
- CLASS B 是我的中央请求处理程序,这个 CLASS B 调用另一个 CLASS C
- CLASS C 是请求的实际服务,在本例中为 login-service -
如您所见,登录子类是静态的。这是一个线程安全的结构吗?
问候
甲级
public class MyStartApplication extends Application {
//Creates a root Restlet that will receive all incoming calls.
@Override
//public synchronized Restlet createInboundRoot() { //synchronized?
public Restlet createInboundRoot() {
//Create a router that routes each call to a new instance of a Resource.
Router router = new Router(getContext());
// First we use MODE_START_WITH to determine the requested destination
// A TRAPDOOR for all requests for this TEST
// We reroute it to THE CENTRAL RESTLET-WRAPPER
TemplateRoute route = router.attach("/testmywrapper/", RestletWrapper.class);
route.getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
// Return the response to caller
return router;
}
}
B类
public class RestletWrapper extends ServerResource {
@Get
public JSONObject start() {
JSONObject returnObj = null;
switch(operation){
case "login":
returnObj= LoginUser.login(queryparams);
break;
}
Return returnObj
}
}
C级
public class LoginUser {
public static JSONObject login(JSONObject queryparams) throws Exception {
do some stuff
return object
}
}