1.Implement a thread-safe (blocking) queue:

Class Producer implements Runable{
Private final BlockingQueue queue;
Producer (BlockingQueue q){queue=q;}
Public void run(){
try{
while(true){queue.put(produce());
}catch(InterruptedException ex){…handle…}
}
Object produce(){…..}
} Class consumer implements runnable{
Private final BlockingQueue queue;
Consumer(BlockingQueue q){queue=q;}
Public void run(){
Try{
While(true){consume(queue.take());}
}catch(InterruptedExpection ex){… handle …}
}
void consumer(Object x){…}
}

2. Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a BlockingQueue happen-before actions subsequent to the access or removal of that element from the BlockingQueue in another thread.

3. What are some ways to implement a singleton in Java

(1)
Public class SingletonObject
{
private Singleton(){ } public static SingletonObject getSingletonObject(){
return ref;
}
} private static SingletonObject ref; (2)
Public class singletonObject{
Private singleton(){}
Public static singletonObject getSingletonObject(){
Return ref;
} }

4.Checked vs unchecked exceptions, finalize

1) Checked: are the exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword. like IOexpection

2) Unchecked are the exceptions that are not checked at compiled time instead of runtime. In C++, all exceptions are unchecked, so it is not forced by the compiler to either handle or specify the exception. It is up to the programmers to be civilized, and specify or catch the exceptions. In Java exceptions under Error and RuntimeException classes are unchecked exceptions, everything else under throwable is checked.

3) Finalize: Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. Also, the garbage collector is not guaranteed to run at any specific time. In general, what I'm trying to say is finalize() is probably not the best method to use in general unless there's something specific you need it for.

5. What is a queue, stack, heap

Queue: FIFO

Stack: FILO, system allocate space on memory

Heap: by using new keyword allocate

6. What happens in the system during a recursive call

Defining recursion is easy – any routine that calls itself is a recursive routine. A call stack is a data structure used by the program to store information about the active subroutines in a program. The main reason for having a call stack is so that the program can keep track of where a subroutine should return control to once it finishes executing. A stack frame is a part of the call stack, and a new stack frame is created every time a subroutine is called. The stack frame is used to store all of the variables for one invocation of a routine.

最新文章

  1. druid 配置
  2. 第一代intel核显id:0046的10.9驱动安装详解(转)
  3. linux rpm 安装和卸载
  4. 网络内容缓存CDN的工作原理
  5. wpf RadioButton控件的一个bug,onpropertychanged后会修改旧属性的值
  6. 中级Perl 第三章课后习题
  7. C++链接库
  8. Codeforces 164 E Compatible Numbers
  9. Nancy简单实战之NancyMusicStore(四):实现购物车
  10. 201521123063 《Java程序设计》 第8周学习总结
  11. httpd路径映射和重定向
  12. Mac 使用 OpenMP/Clang
  13. php 操作mysql
  14. IOT,笔记:avrdude: ser_open(): can't open device "\\.\COM3": 系统找不到指定的文件。
  15. nova系列一:虚拟化介绍
  16. Mybatis 批量插入时得到插入的id(mysql)
  17. Linux内核分析:期中总结
  18. .2 Git 分支 - 分支的新建与合并
  19. mysql 创建用户自定义函数
  20. DataType 枚举

热门文章

  1. 【默默努力】fishingGame
  2. React require(“history”).createBrowserHistory` instead of `require(“history/createBrowserHistory”)
  3. [JZOJ3187]【GDOI2013模拟8】的士
  4. 廖雪峰Java15JDBC编程-3JDBC接口-1JDBC简介
  5. SpringCloud之Fegin学习笔记
  6. Spring MVC(十三)--保存并获取属性参数
  7. day71test
  8. 删除文件夹时提示“You need permission to perform this action。。。”,如何解决?
  9. 11-1-break-continue
  10. fcc筆記