为什么 restful Web 服务在 1 秒后使用相同的 URL 查询顺序调用的执行时间会减少?
Why is execution time of restful web service on calling sequentially after 1 sec with the same URL query decreasing?
我在应用程序服务器 tomcat v 8.0 上使用 Jersy 创建了一个 restful Web 服务,我每 1 秒调用一次 Web 服务
这是我的 restful 网络服务:-
@Path("/db")
public class UserLoginDBRst2
{
DBConnection2 dbCoN;
Connection conn;
ResultSet rslt;
String Iuser="Invalid User";
public static double visitplace2;
@Path("/{latitude}/{longitude}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String LogicUserValidation(@PathParam ("latitude")String lat,@PathParam ("longitude")String longt) throws SQLException
{
long startTime = System.nanoTime();
visitplace2=visitplace2+1;
String lLoginQuery="Select * from place_giver_table where latitude="+ lat + " and longitude="+longt;
dbCoN=new DBConnection2();
try{
conn=DBConnection2.setDBConnection();
rslt=dbCoN.getResultSet(lLoginQuery,conn);
if(rslt.next())
{
String name=rslt.getString(4);
long stopTime = System.nanoTime();
System.out.println(stopTime - startTime);
return name + visitplace2;
}
else
{
long stopTime = System.nanoTime();
System.out.println(stopTime - startTime);
return Iuser + visitplace2;
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
if(conn!=null)
{
conn.close();
}
}
long stopTime = System.nanoTime();
System.out.println(stopTime - startTime);
return Iuser + visitplace2;
}
}
响应时间日志:-
0.221560417
0.017982066
0.017500935
0.024799183
0.016682356
0.020753906
.
.
.
.
0.005201366
0.005475563
0.005381554
0.005084748
0.005325283
0.005599511
我猜存储一些值的缓存内存有问题
在一次又一次地用相同的 url 调用之后,在这种情况下,我也附加了我的 context.xml
这里是META-INF\context.xml:-
<Context antiResourceLocking="false" privileged="true" >
</Context>
希望得到这方面的帮助
提前致谢!
很抱歉给您带来麻烦,我同意 Dirk Lachowski 的观点,即由于缓存,时间正在减少,随着 Web 服务的预热,只建议读取数据。
我在应用程序服务器 tomcat v 8.0 上使用 Jersy 创建了一个 restful Web 服务,我每 1 秒调用一次 Web 服务
这是我的 restful 网络服务:-
@Path("/db")
public class UserLoginDBRst2
{
DBConnection2 dbCoN;
Connection conn;
ResultSet rslt;
String Iuser="Invalid User";
public static double visitplace2;
@Path("/{latitude}/{longitude}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String LogicUserValidation(@PathParam ("latitude")String lat,@PathParam ("longitude")String longt) throws SQLException
{
long startTime = System.nanoTime();
visitplace2=visitplace2+1;
String lLoginQuery="Select * from place_giver_table where latitude="+ lat + " and longitude="+longt;
dbCoN=new DBConnection2();
try{
conn=DBConnection2.setDBConnection();
rslt=dbCoN.getResultSet(lLoginQuery,conn);
if(rslt.next())
{
String name=rslt.getString(4);
long stopTime = System.nanoTime();
System.out.println(stopTime - startTime);
return name + visitplace2;
}
else
{
long stopTime = System.nanoTime();
System.out.println(stopTime - startTime);
return Iuser + visitplace2;
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
if(conn!=null)
{
conn.close();
}
}
long stopTime = System.nanoTime();
System.out.println(stopTime - startTime);
return Iuser + visitplace2;
}
}
响应时间日志:-
0.221560417
0.017982066
0.017500935
0.024799183
0.016682356
0.020753906
.
.
.
.
0.005201366
0.005475563
0.005381554
0.005084748
0.005325283
0.005599511
我猜存储一些值的缓存内存有问题 在一次又一次地用相同的 url 调用之后,在这种情况下,我也附加了我的 context.xml
这里是META-INF\context.xml:-
<Context antiResourceLocking="false" privileged="true" >
</Context>
希望得到这方面的帮助
提前致谢!
很抱歉给您带来麻烦,我同意 Dirk Lachowski 的观点,即由于缓存,时间正在减少,随着 Web 服务的预热,只建议读取数据。