我从ExtJS获得一个日期字符串格式:
"2011-04-08T09:00:00"
当我尝试反序列化此日期时,它会将时区更改为印度标准时间(将时间+5:30添加).这就是我如何反序化日期:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
getObjectMapper().getDeserializationConfig().setDateFormat(dateFormat);
Run Code Online (Sandbox Code Playgroud)
这样做也不会改变时区.我仍然在IST得到日期:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
getObjectMapper().getDeserializationConfig().setDateFormat(dateFormat);
Run Code Online (Sandbox Code Playgroud)
如何在没有时区麻烦的情况下对日期的日期进行反序列化?
在"有效的Java"一书中,Josh Bloch说
StringBuffer在很大程度上已经过时,应该被非同步实现'StringBuilder'取代
.
但根据我的经验,我仍然看到StringBuffer类的广泛使用.为什么StringBuffer类现在已经过时,为什么StringBuilder优先于StringBuffer,除非由于非同步而提高了性能?
我需要优化Java应用程序.它会进行第三方通话.我需要一些好的工具来准确测量各个API调用所花费的时间.为了解复杂性 - 应用程序采用包含100万行的数据源文件,完成处理大约需要一个小时.作为处理的一部分,它会进行一些第三方呼叫(包括一些网络呼叫).我需要确定哪些调用比其他调用花费更多时间,并在此基础上找到优化应用程序的方法.
任何建议,将不胜感激.
当我开始我的项目时,我不知道Maven ..在项目已经发展到相当大的规模之后,我意识到了它的重要性.那时我真的快速发展,因此我并不想打破这种流动.所以,我推迟将maven插入到项目中.现在我有一点呼吸空间,所以我想将maven添加到项目中.
你建议我做什么或者我应该做什么?我在项目中有Spring,Struts,Log4J,Hibernate和JAX-RS.
为什么我们在使用时会丢失类型安全性List而不是在使用时List<Object>?他们基本上不一样吗?
编辑:我发现以下给出了编译错误
public class TestClass
{
static void func(List<Object> o, Object s){
o.add(s);
}
public static void main(String[] args){
func(new ArrayList<String>(), new Integer(1));
}
}
Run Code Online (Sandbox Code Playgroud)
而事实并非如此
public class TestClass
{
static void func(List o, Object s){
o.add(s);
}
public static void main(String[] args){
func(new ArrayList<String>(), new Integer(1));
}
}
Run Code Online (Sandbox Code Playgroud)
为什么?
运行此程序时为什么会出现此错误?这发生在随机迭代之后.通常在第8000次迭代之后.
public static void main(String[] args)
{
FileWriter writer = null;
try
{
for(int i = 0; i < 10000; i++)
{
File file = new File("C:\\Users\\varun.achar\\Desktop\\TODO.txt");
if(file.exists())
{
System.out.println("File exists");
}
writer = new FileWriter(file, true);
writer.write(i);
System.out.println(i);
writer.close();
if(!file.delete())
{
System.out.println("unable to delete");
}
//Thread.sleep(10);
//writer = null;
//System.gc();
}
}
catch(IOException e)
{
e.printStackTrace();
}
finally
{
if(writer != null)
{
try
{
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
发生异常后,该文件不存在.这意味着它正在删除,但FIleWriter尝试在此之前获取锁,即使它不是多线程程序.是因为Windows没有足够快地删除文件,因此FileWriter没有锁定?如果是这样,那么file.delete()方法在Windows实际删除之前返回?
我如何解决它,因为我在负载测试我的应用程序时遇到了类似的问题.
编辑1:Stacktrace:
java.io.FileNotFoundException: …Run Code Online (Sandbox Code Playgroud) 是否有可能使编译器在遇到用户定义的注释时生成警告?类似于@Deprecated注释的东西?
谢谢
用户登录成功后,我需要在DB中存储实际日期.怎么做 ?过滤器,处理器还是什么?需要帮忙.
我想知道如何在使用hibernate生成POJO时更改其名称.
我的表的命名约定为:FR_和TRN_.在生成POJO时,我想删除FR和TRN并将VO附加到名称上.
例如,
表名:FR_ACCOUNT_MST
要生成的POJO:accountMstVO
谢谢,瓦伦
编辑:添加:http : //jsfiddle.net/bfNzH/1/
我的HTML的结构如下:
<body>
<div class="wrapper">
<div class="left">left bar</div>
<div class="right">
<div class="topbar">topbar</div>
<div class="header">header</div>
<div class="content">
<div>..some stuff</div>
<table>
<thead>
<tr>
<th class="th1">Col1</th>
<th>Col2</th>
<th>Col3</th>
<th>Col4</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
的CSS
body {
height : 100%;
}
.wrapper {
position : absolute;
top : 0;
bottom : 0;
left : 0;
right : 0;
overflow : hidden;
}
.left {
height : 100%;
position : absolute;
width : 50px;
overflow : hidden; …Run Code Online (Sandbox Code Playgroud) 我正在尝试模拟DateTimeFormatter类.我做了以下事情:
@RunWith(PowerMockRunner.class)
@PrepareForTest({DateTimeFormatter.class})
public class UnitTest {
private DateTimeFormatter mockDateFormatter;
private AwesomeClass awesomeClass;
@Before
public void setUp() {
mockDateFormatter = PowerMockito.mock(DateTimeFormatter.class);
awesomeClass = new AwesomeClass(mockDateFormatter);
}
@Test
public void shouldToTestSomethingAwesome() {
// Other test code
PowerMockito.when(mockDateFormatter.format(any(LocalDate.class)))
.thenReturn("20150224");
// Other test code
}
Run Code Online (Sandbox Code Playgroud)
AwesomeClass用它来格式化LocalDateTime.now(ZoneId.of("UTC"));.然后,格式化的字符串进一步用于生成另一个字符串.我需要确保正确生成字符串.所以我需要从格式化程序返回一致的日期或模拟LocalDateTime.now(..)静态方法
我究竟做错了什么?
java ×9
annotations ×1
css ×1
css-position ×1
datetime ×1
file-io ×1
generics ×1
git ×1
git-checkout ×1
hibernate ×1
html ×1
jackson ×1
json ×1
maven ×1
mockito ×1
performance ×1
pojo ×1
powermock ×1
profiling ×1
spring ×1
string ×1
stringbuffer ×1
warnings ×1