我想在特定日期添加一天.我怎样才能做到这一点?
Date dt = new Date();
Run Code Online (Sandbox Code Playgroud)
现在我想在这个日期添加一天.
我有一个返回List期货的方法
List<Future<O>> futures = getFutures();
Run Code Online (Sandbox Code Playgroud)
现在我想要等到所有期货都成功处理完成,或者将来输出的任何任务抛出异常.即使一个任务抛出异常,也没有必要等待其他期货.
简单的方法是
wait() {
For(Future f : futures) {
try {
f.get();
} catch(Exception e) {
//TODO catch specific exception
// this future threw exception , means somone could not do its task
return;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是,例如,如果第四个未来抛出异常,那么我将不必要地等待前3个期货可用.
怎么解决这个?会以任何方式倒数闩锁帮助吗?我无法使用Future,isDone因为java doc说
boolean isDone()
Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.
Run Code Online (Sandbox Code Playgroud) 我正在使用Picasso在我的Android应用程序中显示图像:
/**
* load image.This is within a activity so this context is activity
*/
public void loadImage (){
Picasso picasso = Picasso.with(this);
picasso.setDebugging(true);
picasso.load(quiz.getImageUrl()).into(quizImage);
}
Run Code Online (Sandbox Code Playgroud)
我已启用调试,它始终显示红色和绿色.但从不显示黄色
现在,如果我下次加载相同的图像并且互联网不可用,则不会加载图像.
问题:
为什么我在Hibernate中需要Transaction才能进行只读操作?
以下事务是否锁定了数据库?
从DB获取的示例代码:
Transaction tx = HibernateUtil.getCurrentSession().beginTransaction(); // why begin transaction?
//readonly operation here
tx.commit() // why tx.commit? I don't want to write anything
Run Code Online (Sandbox Code Playgroud)
我可以用session.close() 而不是tx.commit()吗?
我有一个受支持的片段活动,它将加载diff片段.片段有一些textView,id = "score"我希望得到它的句柄,但findViewById得分的textView返回null.为什么这样?
textView放在片段中
public class MyActivity extends extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks{
private TextView scoreBoardTextView = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
scoreBoardTextView = (TextView) findViewById(R.id.score); //this returns null
}
@Override
public void onNavigationDrawerItemSelected(int position) {
//set fragment
}
}
Run Code Online (Sandbox Code Playgroud) 我在尝试第一个春季项目时遇到以下错误:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan
Run Code Online (Sandbox Code Playgroud)
这是applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="com.xyz" />
</beans>
Run Code Online (Sandbox Code Playgroud)
是什么导致错误?
我想检查我的字符串是否包含+字符.我尝试了以下代码
s= "ddjdjdj+kfkfkf";
if(s.contains ("\\+"){
String parts[] = s.split("\\+);
s= parts[0]; // i want to strip part after +
}
Run Code Online (Sandbox Code Playgroud)
但它没有给出预期的结果.任何想法?
我怎样才能转换Date成DateTime反之亦然?
例如
Date dt = new Date();
Run Code Online (Sandbox Code Playgroud)
现在我想转发它DateTime.
也
DateTime dtim = new DateTime();
Run Code Online (Sandbox Code Playgroud)
现在我想将它转换为Date.