以下函数生成今天的日期; 我怎么能让它只生产昨天的日期?
private String toDate() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
return dateFormat.format(date).toString();
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
2012-07-10
Run Code Online (Sandbox Code Playgroud)
我只需要昨天的日期,如下所示.可以在我的功能中执行此操作吗?
2012-07-09
Run Code Online (Sandbox Code Playgroud) 在Java中,我们可以使用System.currentTimeMillis()以纪元时间为单位获取当前时间戳,以毫秒为单位 -
当前时间与UTC时间1970年1月1日午夜之间的差值,以毫秒为单位.
在C++中如何获得相同的东西?
目前我用它来获取当前时间戳 -
struct timeval tp;
gettimeofday(&tp, NULL);
long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
cout << ms << endl;
Run Code Online (Sandbox Code Playgroud)
看起来对不对?
我每天凌晨5点都在尝试完成某项任务.所以我决定使用ScheduledExecutorService这个,但到目前为止,我已经看到了一些示例,显示了如何每隔几分钟运行一次任务.
而且我无法找到任何显示如何在早上的特定时间(早上5点)每天运行任务的例子,同时也考虑夏令时的事实 -
以下是我的代码,每15分钟运行一次 -
public class ScheduledTaskExample {
private final ScheduledExecutorService scheduler = Executors
.newScheduledThreadPool(1);
public void startScheduleTask() {
/**
* not using the taskHandle returned here, but it can be used to cancel
* the task, or check if it's done (for recurring tasks, that's not
* going to be very useful)
*/
final ScheduledFuture<?> taskHandle = scheduler.scheduleAtFixedRate(
new Runnable() {
public void run() {
try {
getDataFromDatabase();
}catch(Exception ex) {
ex.printStackTrace(); //or loggger would be …Run Code Online (Sandbox Code Playgroud) 我试图在java中解析一个JSON字符串,以单独打印单个值.但是在程序运行的同时我得到以下错误 -
Exception in thread "main" java.lang.RuntimeException: Stub!
at org.json.JSONObject.<init>(JSONObject.java:7)
at ShowActivity.main(ShowActivity.java:29)
Run Code Online (Sandbox Code Playgroud)
我的班级看起来像 -
import org.json.JSONException;
import org.json.JSONObject;
public class ShowActivity {
private final static String jString = "{"
+ " \"geodata\": ["
+ " {"
+ " \"id\": \"1\","
+ " \"name\": \"Julie Sherman\","
+ " \"gender\" : \"female\","
+ " \"latitude\" : \"37.33774833333334\","
+ " \"longitude\" : \"-121.88670166666667\""
+ " }"
+ " },"
+ " {"
+ " \"id\": \"2\","
+ " \"name\": \"Johnny Depp\","
+ " …Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,其中我有多个接口和两个实现类,需要实现这两个接口.
假设我的第一个接口是 -
public Interface interfaceA {
public void abc() throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
它的实施是 -
public class TestA implements interfaceA {
// abc method
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼它 -
TestA testA = new TestA();
testA.abc();
Run Code Online (Sandbox Code Playgroud)
现在我的第二个界面是 -
public Interface interfaceB {
public void xyz() throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
它的实施是 -
public class TestB implements interfaceB {
// xyz method
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼它 -
TestB testB = new TestB();
testB.xyz();
Run Code Online (Sandbox Code Playgroud)
问题陈述:-
现在我的问题是 - 有什么办法,我可以并行执行这两个实现类吗?我不想按顺序运行它.
意思是,我想并行运行TestA和TestB实现?这可能吗?
我想在这里使用Callable但不知道如何在这里使用带有void返回类型的Callable -
我们以TestB类为例:
public interface interfaceB …Run Code Online (Sandbox Code Playgroud) 解析后我的文件"s"包含 AttributeGet:1,16,10106,10111
所以我需要在attributeIDGet List中获取冒号后面的所有数字.我知道有几种方法可以做到这一点.但是我们有什么方法可以直接转换List<String>为List<Integer>.
由于下面的代码抱怨类型不匹配,所以我尝试做Integer.parseInt,但我想这对List不起作用.这是s字符串.
private static List<Integer> attributeIDGet = new ArrayList<Integer>();
if(s.contains("AttributeGet:")) {
attributeIDGet = Arrays.asList(s.split(":")[1].split(","));
}
Run Code Online (Sandbox Code Playgroud) 我在Windows环境中工作.每次我使用tomcat时都会收到此错误
Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@4ae53a99
2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection: Reconnecting due to failure to connect to {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connection refused: no further information
Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
Exception in thread "Memcached IO over {MemcachedConnection to localhost/127.0.0.1:11211}" java.lang.OutOfMemoryError: …Run Code Online (Sandbox Code Playgroud) 有谁可以请帮助我如何解决此错误:
Native code library failed to load.
java.lang.UnsatisfiedLinkError: no ts-jni in java.library.path
Run Code Online (Sandbox Code Playgroud)
我是第一次使用IDEA IDE,并且一直使用Resin_4.0.37作为服务器来测试我的工作.一旦我在调试模式下启动我的lcoal服务器,它会停留大约1-2分钟,然后突然它下降并通过给我上述错误而断开连接.
我正确设置了我的Windows环境变量; 并且还在我的IDE intelliJ中执行了以下操作:
FILE->Project Structure->set Global Libraries->a. Java path and b. Resin library path.
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我,我做错了什么,如何在intelliJ IDEA中设置本机库来解决上述错误.
任何帮助,将不胜感激.如果我做错了,也要纠正我.
谢谢!
我正在调用REST URL并尝试测量恢复响应所花费的时间.
我正在用DefaultHttpClient它来获得回复REST URL.
在我的下面的程序中,每个线程将在特定范围内工作.像每个线程将工作之间1 - 100和第二个线程将工作之间101 - 200等.
在我的下面的代码中,它第一次正常工作.但这是第二次,它在这条线上httpclient.execute第二次抛出异常-
java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗? -
以下是我的代码 -
class Task implements Runnable {
private DefaultHttpClient httpclient = new DefaultHttpClient();
private HttpGet httpGet;
private HttpResponse response;
@Override
public void run() {
try {
httpGet = new HttpGet(
"http://localhost:8080/service/BEService/v1/get/USERID=10000/profile.ACCOUNT.SERVICE
httpGet.getRequestLine();
for (int userId = id; userId < id …Run Code Online (Sandbox Code Playgroud) Student.jar我Build Path在我的日食中添加了一个像这样的 -
右键单击项目 - > BuildPath-> Configure Build Path-> Libraries-> Add External Jars
有一个名为一类StudentTest的Student.jar文件.当我在eclipse中调试我的代码时,我进入了那个StudentTest类Student.jar.
之后的日食就像这样 -
JAR文件
S:\some_location\Student.jar没有源附件.您可以通过单击下面的"附加源"来附加源
现在我不确定我应该如何在日食中附加来源.从哪里来?任何人都可以一步一步地向我提供我需要做的事情.
更新: -
我尝试解压缩Student.jar,我得到了Student folder.之后我尝试将源指向Student folder但仍然无法正确查看类,以便我可以正确调试它,它显示了相同的上述行为.