StackOverflow 常见问题
来源:互联网 发布:千寻位置网络 编辑:程序博客网 时间:2024/06/01 08:44
stackoverflow 常见问题
1 java
1.1 Java += operator
Question:
int i = 5;
long j = 8;
Then i = i + j; will not compile but i += j; will compile fine.
Does it mean that in fact i += j; is a shortcut for something like this i = (type of i) (i + j)?
I've tried googling for it but couldn't find anything relevant.
Answer:
A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.
[...] the following code is correct:
short x = 3;
x += 4.6;
and results in x having the value 7 because it is equivalent to:
short x = 3;
x = (short)(x + 4.6);
1.2 Creating a memory leak with Java
Question:
I just had an interview, and I was asked to create a memory leak with Java. Needless to say I felt pretty dumb having no clue on how to even start creating one.
What would an example be?
Answer:
Here's a good way to create a true memory leak (objects inaccessible by running code but still stored in memory) in pure Java:
The application creates a long-running thread (or use a thread pool to leak even faster).
The thread loads a class via an (optionally custom) ClassLoader.
The class allocates a large chunk of memory (e.g. new byte[1000000]), stores a strong reference to it in a static field, and then stores a reference to itself in a ThreadLocal. Allocating the extra memory is optional (leaking the Class instance is enough), but it will make the leak work that much faster.
The thread clears all references to the custom class or the ClassLoader it was loaded from.
Repeat.
This works because the ThreadLocal keeps a reference to the object, which keeps a reference to its Class, which in turn keeps a reference to its ClassLoader. The ClassLoader, in turn, keeps a reference to all the Classes it has loaded. It gets worse because in many JVM implementations Classes and ClassLoaders are allocated straight into permgen and are never GC'd at all.
A variation on this pattern is why application containers (like Tomcat) can leak memory like sieve if you frequently redeploy applications that happen to use ThreadLocals in any way. (Since the application container uses Threads as described, and each time you redeploy the application a new ClassLoader is used.)
1.3 What is the difference between Left, Right, Outer and Inner Joins?
Answer:
1.4 Why does this go into an infinite loop?
public class Tests {
public static void main(String[] args) throws Exception {
int x = 0;
while(x<3) {
x = x++;
System.out.println(x);
}
}
}
1.5 ORA-00060: deadlock detected while waiting for resource
参阅:http://www.oratechinfo.co.uk/deadlocks.html
常见产生死锁的原因:
1.互斥等待The "classic" deadlock
2.自治事务 Deadlocks with Autonomous Transactions
3.位图索引Deadlocks with Bitmap Indexes
4.外键无索引Deadlocks with unindexed foreign keys
- StackOverflow 常见问题
- StackOverFlow
- StackOverflow
- Hi,STACKOVERFLOW
- Emacs -- stackoverflow
- Stackoverflow学习
- Stackoverflow Error
- Stackoverflow Error
- stackoverflow重要性
- Stackoverflow OutOfMemoryError
- Stackoverflow使用
- stackoverflow問題集
- 调试 堆栈溢出. stackoverflow
- 中国的stackoverflow
- stackoverflow.com stackchange.com
- StackOverFlow精选问答集锦
- StackOverflow问答收藏
- 上不了stackoverflow
- DedeCMS自定义时间字段调用方法
- ios更改Xcode配置
- Kernal-Based Object Tracking---基于核函数的目标跟踪
- Chrome浏览器开发调试系列(一)
- python3.x之print()不换行解决方案
- StackOverflow 常见问题
- 百度是如何给每个人免费提供2TB存储空间的?
- Visual Studio Ultimate 2012: 使用 Code Map 理解复杂代码
- Hadoop对各个节点的角色定义
- 黑马程序员_学习笔记:6) 异常、包
- IBM王天�:中国金融业应用历程和未来 - 51CTO.COM
- 杭电1875
- java
- nfc i2c测试