ITeye博客

java

共 80 篇文章

Java enum type

In the following example, Planet is an enum type that represents the planets in the solar system. They are defined with constant mass and radius properties. Each enum constant is declared with values for the mass and radius parameters. These values are passed to the constructor when the constant is…

2010-08-31 11:22 · java

Use JNI for safer java servers

http://www2.sys-con.com/itsg/virtualcd/Java/archives/0510/Silverman/index.html

2010-08-11 08:45 · java

Java Native Interface (JNI) - JNI javah error : class file contains wrong class

http://forums.sun.com/thread.jspa?threadID=709403 On how java tools find user classes: A class/java file has a subpath name that reflects the class's fully-qualified name. For example, if the class com.mypackage.MyClass is stored under /myclasses, then /myclasses must be in the user class path and …

2010-08-06 08:26 · java

Mount options to improve ext4 file system performance

Mount options to improve ext4 file system performance

2010-07-29 09:52 · java

Efficient data transfer through zero copy

http://www.ibm.com/developerworks/linux/library/j-zerocopy/ http://www.linuxjournal.com/article/6345?page=0,1

2010-03-19 10:47 · java

java程序员面试必备的32个要点

很经典的东西,被转的到处都是, 先写原文: 第一,谈谈final, finally, finalize的区别。 final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。finally是异常处理语句结构的一部分,表示总是执行。finalize是 Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。 第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 可以继承其他类或完成其…

2010-02-08 13:16 · java

java5中使用interrupt()来停止java线程的方法

在开发java多线程时,如果要停止线程这个问题很头痛吧,不过在Java5的java.util.concurrent中使用interrupt(),让线程在run方法中停止。 简介 在Java的多线程编程中,java.lang.Thread类型包含了一些列的方法start(), stop(), stop(Throwable) and suspend(), destroy() and resume()。通过这些方法,我们可以对线程进行方便的操作,但是这些方法中,只有start()方法得到了保留。 在Sun公司的一篇文章《Why are Thread.stop, Thread.suspend and…

2010-02-08 09:52 · java

wait()和sleep()的区别

这两者的施加者是有本质区别的. sleep()是让某个线程暂停运行一段时间,其控制范围是由当前线程决定,也就是说,在线程里面决定.好比如说,我要做的事情是 "点火->烧水->煮面",而当我点完火之后我不立即烧水,我要休息一段时间再烧.对于运行的主动权是由我的流程来控制. 而wait(),首先,这是由某个确定的对象来调用的,将这个对象理解成一个传话的人,当这个人在某个线程里面说"暂停!",也是 thisOBJ.wait(),这里的暂停是阻塞,还是"点火->烧水->煮饭",thisOBJ就好比一个监督我的人站在我旁边,本来该线 程应该执行1后执行2,再执行3,而在2处被那个对象喊暂停,那么我就会…

2010-02-08 08:57 · java

JAVA网络编程问题剖析

我所说的网络编程就是指Socket编程,首先列举一下用JAVA语言编写Socket程序时的常见异常、原因及解决方法,然后再讲一下编写网络程序需要注意的问题。在分析之前,首先把网络程序中所谓的客户端和服务器弄清楚,它们是在通信层面的,所谓的服务器是接收连接的应用,而所谓的客户是发起连接的应用,与业务层面的客户端和服务器并非一一对应,在实际系统中业务层面的服务器端可能是网络层面客户端。下文所说的服务器和客户端是网络层面的。(本文并不准备对TCP/UDP、java.net包中的API和网络连接建立的过程进行说明) 一.网络程序运行过程中的常见异常及处理 第1个异常是java.net.BindExc…

2009-10-12 13:35 · java

Multithreading in Java (10)

Multithreading in Java - Suspending and Resuming Threads (Page 10 of 10 ) There might be times when you need to temporarily stop a thread from processing and then resume processing, such as when you want to let another thread use the current resource. You can achieve this objective by defining your…

2009-09-24 09:51 · java

Multithreading in Java (9)

Multithreading in Java - Using the Synchronized Statement (Page 9 of 10 ) Synchronizing a method is the best way to restrict the use of a method one thread at a time. However, there will be occasions when you won’t be able to synchronize a method, such as when you use a class that is provided to yo…

2009-09-24 09:48 · java

Multithreading in Java (8)

Multithreading in Java - Synchronizing Threads (Page 8 of 10 ) A major concern when two or more threads share the same resource is that only one of them can access the resource at one time. Programmers address this concern by synchronizing threads, much the same way baseball players take turns bein…

2009-09-24 09:41 · java

Multithreading in Java (7)

Multithreading in Java - Setting Thread Priorities (Page 7 of 10 ) Previously in this chapter, you learned that each thread has an assigned priority that is used to let more important threads use resources ahead of lower-priority resources. Priority is used as a guide for the operating system to de…

2009-09-24 09:23 · java

Multithreading in Java (6)

Multithreading in Java - Using isAlive() and join() (Page 6 of 10 ) Typically, the main thread is the last thread to finish in a program. However, there isn’t any guarantee that the main thread won’t finish before a child thread finishes. In the previous example, we told the main method to sleep un…

2009-09-24 09:16 · java

Multithreading in Java (5)

Multithreading in Java - Creating a Thread by Using extends (Page 5 of 10 ) You can inherit the Thread class as another way to create a thread in your program. As you’ll recall from Chapter 8, you can cause your class to inherit another class by using the keyword extends when defining your class. W…

2009-09-24 09:12 · java

Multithreading in Java (4)

Multithreading in Java - Creating Your Own Thread (Page 4 of 10 ) Remember, your program is the main thread, and other portions of your program can also be a thread. You can designate a portion of your program as a thread by creating your own thread. The easiest way to do this is to implement the R…

2009-09-23 23:07 · java

Multithreading in Java (3)

Multithreading in Java - The Thread Classes and the Runnable Interface (Page 3 of 10 ) You construct threads by using the Thread class and the Runnable interface. This means that your class must extend the Thread class or implement the Runnable interface. The Thread class defines the methods you us…

2009-09-23 23:06 · java

Multithreading in Java (2)

Multithreading in Java - Overhead (Page 2 of 10 ) The operating system must do extra work to manage multitasking. Programmers call this extra work overhead because resources inside your computer are used to manage the multitasking operation rather than being used by programs for processing instruct…

2009-09-23 23:04 · java

Multithreading in Java (1)

Multithreading allows two parts of the same program to run concurrently. This article discusses how to pull off this performance-improving feat in Java. It is excerpted from chapter 10 of the book Java Demystified , written by Jim Keogh (McGraw-Hill/Osborne, 2004; ISBN: 0072254548). Marathon runner…

2009-09-23 23:01 · java

java dynamic proxy class

A dynamic proxy class (simply referred to as a proxy class below) is a class that implements a list of interfaces specified at runtime when the class is created, with behavior as described below. A proxy interface is such an interface that is implemented by a proxy class. A proxy instance is an ins…

2009-07-23 21:30 · java