はじめに:私はオープンソースソフトウェアの初心者です。(Apache-Tomcat / Java / Restletframework)
ここに私の質問があります:私はRestletフレームワークでアプリケーションを構築しています。私のコーディング/方法論がスレッドセーフかどうかわかりません!?誰かが私が正しい方法でコーディングしているかどうか教えてもらえますか?それとも私は絶望的に失敗していますか?
構成:
- クラスAはクライアントによって呼び出されます。(RESTリクエスト)
- クラスA(ルーター)はクラスBを呼び出します
- クラスBは私の中央リクエストハンドラです。このクラスBは別のクラスCを呼び出します
- CLASS Cは、要求された実際のサービスです。この例では、login-service-
ご覧のとおり、ログインサブクラスは静的です。これはスレッドセーフな構造ですか?
よろしく
クラスA
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
}
}