multithreading - Implement Java Web Server with database, GCM and background threads -
multithreading - Implement Java Web Server with database, GCM and background threads -
i trying create web server provides web service functions, communicates android devices using gcm, uses database , has background work do.
i unsure on architecture of such server. know how create simple web service, have not found tutorials or descriptions go beyond simple "hello world" examples. far know can create class @webservice annotation, , 1 time deployed e.g. tomcat server create @ to the lowest degree 1 instance of class , provide annoteted functions in class web services.
now wonder how best implement database connection. know server create instance of class every request, wich garbage collected 1 time connection closed. since web server needs database every function provides think not thought create database connection every instance, rather utilize global connection query database. found out far achieved injecting class handles database connection @resource or @singleton web service class. proper way ? or worring much , creating new database connection each request fine ?
then want send gcm messages (the simple post ones using html google server), create controller or manager class handle these requests. injected @resource or @singleton web service class ?
and lastly not to the lowest degree server has work periodicaly, wich kind of background thread, independant of requests web service recieving. here @ loss on how this. web service not have main() method aware of, unsure on how create this.
can give me guick overview on how design such web server or can point me documentation describe on how accomplish ? found far simple examples don't cover advanced stuff this.
ok, have 3 questions/problems.
how create webservice how manage database connections execute batch processall of this, in same app. first of all, should advice split 2 app, 1 consume (web services) , batch processing, including force notifications (imho). lets go 1 step @ time.
1. webservice: it's depends on framework choose. made selection between spring-mvc or jersey
2. how manage database connections when querying database, don't want open , close connections crazily. want utilize connection pool. in connection pool you'll inquire open connection, utilize it, , free when done. normally, connection pool managed por application server. if want manage connections manually, have utilize singleton centralise acquiring , releasing.
3. execute batch process should utilize singleton manage batch process. job manager launch job executions on other threads
don't know if answers question/concern.. please allow me know.
java multithreading web-services
Comments
Post a Comment