Xiaobo Sun

Eclipse-Unix http://umlfact.berlios.de/~s_xsun/

VM shared folder

Shared Folders是Vmware4 的一个新功能,更加方便了在Host,Guest操作系统间共享文件。它是把Host机器上的一个目录共享给Guest机器使用。点击Edit- >;Virtual machine settigns->;Option->;Shared Folders->;Add,选定要共享的文件夹并给这个文件夹命名,下一步。选定“Enable this share”,还有只读和重启后失效的选项,根据需要选择。
确定以后,vmware会把这个文件夹自动mount到/mnt/hgfs目录下

posted @ 2008-05-18 10:10 Xiaobo Sun 阅读(570) | 评论 (0)编辑 收藏

虚拟语气

1. 德语
1)非现实
Wenn das Wetter doch schoen waere!
Wenn wir jetzt Ferien haetten!

Wenn ich Zeit haette, kaeme ich gerne zur einer Party.
Wenn ich Zeit haette, wuerde ich gerne zur einer Party kommen.
2) 客气
Haettest du Lust zu einer Party?
Koennten Sie...
Duerfte ich...

2.英语
1)条件从句:If I were you, I would(should,could,might) study hard.
2) wish宾语:I wish I were as young as you.
3) suggest, advise, ask, decide..宾语:I advise that we (should) stay and wait here.

posted @ 2008-05-13 14:10 Xiaobo Sun 阅读(176) | 评论 (0)编辑 收藏

Dom


posted @ 2008-02-28 14:00 Xiaobo Sun 阅读(226) | 评论 (0)编辑 收藏

Thread and Runnable

Thread is the 进程, Runnable is the 进程对象

[第一需要弄清的问题]

  如同程序和进程的区别,要掌握多线程编程,第一要弄清的问题是:线程对象和线程的区别

  线程对象是可以产生线程的对象。比如在java平台中Thread对象,Runnable对象。线程,是指正在执行的一个指点令序列。在java平台上是指从一个线程对象的start()开始,运行run方法体中的那一段相对独立的过程。

  鉴于作者的水平,无法用更确切的词汇来描述它们的定义。但这两个有本质区别的概念请初学者细细体会,随着介绍的深入和例程分析的增加,就会慢慢明白它们所代表的真实含义。

  天下难事必始于易,天下大事必始于细。

  让我们先从最简单的"单线程"来入手:(1)带引号说明只是相对而言的单线程,(2)基于java。

    class BeginClass{
public static void main(String[] args){
for(int i=0;i<100;i++)
System.out.println("Hello,World!");
}
}

  如果我们成功编译了该java文件,然后在命令行上敲入:

  java BeginClass

  现在发生了什么呢?每一个java程序员,从他开始学习java的第一分钟里都会接触到这个问

  题,但是,你知道它到底发生发什么?

JVM进程被启动,在同一个JVM进程中,有且只有一个进程,就是它自己。然后在这个JVM环境中,所有程序的运行都是以线程来运行。JVM最先会产生 一个主线程,由它来运行指定程序的入口点。在这个程序中,就是主线程从main方法开始运行。当main方法结束后,主线程运行完成。JVM进程也随之退 出。

  我们看到的是一个主线程在运行main方法,这样的只有一个线程执行程序逻辑的流程我们称

  之为单线程。这是JVM提供给我们的单线程环境,事实上,JVM底层还至少有垃圾回收这样的后台线程以及其它非java线程,但这些线程对我们而言不可访问,我们只认为它是单线程的。

  主线程是JVM自己启动的,在这里它不是从线程对象产生的。在这个线程中,它运行了main方法这个指令序列。理解它,但它没有更多可以研究的内容。

  [接触多线程]

    class MyThread extends Thread{
public void run(){
System.out.println("Thread say:Hello,World!");
}
}

public class MoreThreads{
public static void main(String[] args){
new MyThread();
new MyThread().start();
System.out.println("Main say:Hello,World");
}
}

  执行这个程序,main方法第一行产生了一个线程对象,但并没有线程启动。

  main方法第二行产生了一个线程对象,并启动了一个线程。

  main方法第三行,产生并启动一个线程后,主线程自己也继续执行其它语句。

  我们先不研究Thread对象的具体内容,稍微来回想一下上面的两个概念,线程对象线程。在JAVA中,线程对象是JVM产生的一个普通的Object子类。而线程是CPU分配给这个对象的一个运行过程。我们说的这个线程在干什么,不是说一个线程对象在干什么,而是这个运行过程在干什么。如果一时想不明白,不要急,但你要记得它们不是一回事就行了。


现在我们来开始考察JAVA中线程对象。

  在JAVA中,要开始一个线程,有两种方式。一是直接调用Thread实例的start()方法,二是
将Runable实例传给一个Thread实例然后调用它的start()方法。

  在前面已经说过,线程对象和线程是两个完全不同的概念。这里我们再次深入一下,生成一个线程的实例,并不代表启动了线程。而启动线程是说在某个线程对象上启动了该实例对应的线程,当该线程结束后,并不会就立即消失。

  对于从很多书籍上可以看到的基础知识我就不用多说了。既然是基础知识,我也着重于从普通文档上读不到的内容。所以本节我重点要说的是两种线程对象产生线程方式的区别。

class MyThread extends Thread{
public int x = 0;

public void run(){

for(int i=0;i<100;i++){
try{
Thread.sleep(10);
}catch(Exception e){}
System.out.println(x++);

}
}
}

  如果我们生成MyThread的一个实例,然后调用它的start()方法,那么就产生了这个实例对应的线程:

public class Test {
public static void main(String[] args) throws Exception{
MyThread mt = new MyThread();
mt.start();
}
}

  不用说,最终会打印出0到99,现在我们稍微玩一点花样:

public class Test {
public static void main(String[] args) throws Exception{
MyThread mt = new MyThread();
mt.start();
System.out.println(101);
}
}

  也不用说,在基础篇(一)中我们知道由于单CPU的原因,一般会先打印101,然后打印0到99。不过我们可以控制线程让它按我们的意思来运行:

public class Test {
public static void main(String[] args) throws Exception{
MyThread mt = new MyThread();
mt.start();
mt.join();
System.out.println(101);
}
}

  好了,我们终于看到,mt实例对应的线程(假如我有时说mt线程请你不要怪我,不过我尽量不这么说)。在运行完成后,主线程才打印101。因为 我们让当前线程(这里是主线程)等待mt线程的运行结束。"在线程对象a上调用join()方法,就是让当前正在执行的线程等待线程对象a对应的线程运行 完成后才继续运行。" 请大家一定要深刻理解并熟记这句话,而我这里引出这个知识点的目的是为了让你继续看下面的例子:

public class Test {
public static void main(String[] args) throws Exception{
MyThread mt = new MyThread();
mt.start();
mt.join();
Thread.sleep(3000);
mt.start();
}
}

  当线程对象mt运行完成后,我们让主线程休息一下,然后我们再次在这个线程对象上启动线程。结果我们看到:

  Exception in thread "main" java.lang.IllegalThreadStateException

  也就是这种线程对象一时运行一次完成后,它就再也不能运行第二次了。我们可以看一下它有具体实现:

    public synchronized void start() {
if (started)
throw new IllegalThreadStateException();
started = true;
group.add(this);
start0();
}

  一个Thread的实例一旦调用start()方法,这个实例的started标记就标记为true,事实中不管这个线程后来有没有执行到底,只要调用了一次start()就再也没有机会运行了,这意味着:

[通过Thread实例的start(),一个Thread的实例只能产生一个线程]

  那么如果要在一个实例上产生多个线程(也就是我们常说的线程池),我们应该如何做呢?这就是Runnable接口给我们带来的伟大的功能。

class R implements Runnable{
private int x = 0;
public void run(){

for(int i=0;i<100;i++){
try{
Thread.sleep(10);
}catch(Exception e){}
System.out.println(x++);

}
}
}

  
正如它的名字一样,Runnable的实例是可运行的,但它自己并不能直接运行,它需要被Thread对象来包装才行运行:

public class Test {
public static void main(String[] args) throws Exception{
new Thread(new R()).start();
}
}

  当然这个结果和mt.start()没有什么区别。但如果我们把一个Runnable实例给Thread对象多次包装,我们就可以看到它们实际是在同一实例上启动线程:

public class Test {
public static void main(String[] args) throws Exception{
R r = new R();
for(int i=0;i<10;i++)
new Thread(r).start();
}
}

  x是实例对象,但结果是x被加到了999,说明这10个线程是在同一个r对象上运行的。请大家注意,因为这个例子是在单CPU上运行的,所以没 有对多个线程同时操作共同的对象进行同步。这里是为了说明的方便而简化了同步,而真正的环境中你无法预知程序会在什么环境下运行,所以一定要考虑同步。

  到这里我们做一个完整的例子来说明线程产生的方式不同而生成的线程的区别:

package debug;

import java.io.*;
import java.lang.Thread;


class MyThread extends Thread{
public int x = 0;

public void run(){
System.out.println(++x);
}
}

class R implements Runnable{
private int x = 0;
public void run(){
System.out.println(++x);
}
}

public class Test {
public static void main(String[] args) throws Exception{

for(int i=0;i<10;i++){
Thread t = new MyThread();
t.start();
}
Thread.sleep(10000);//让上面的线程运行完成
R r = new R();
for(int i=0;i<10;i++){
Thread t = new Thread(r);
t.start();
}
}
}

  上面10个线程对象产生的10个线程运行时打印了10次1。下面10个线程对象产生的10个线程运行时打印了1到10。我们把下面的10个线程称为同一实例(Runnable实例)的多个线程



posted @ 2008-02-28 13:57 Xiaobo Sun 阅读(2261) | 评论 (0)编辑 收藏

Eclipse Workbench




posted @ 2008-02-28 13:31 Xiaobo Sun 阅读(236) | 评论 (0)编辑 收藏

TCP connect/deconnect

Wireshark is a powerful tool..
.

posted @ 2008-02-28 13:24 Xiaobo Sun 阅读(194) | 评论 (0)编辑 收藏

Display.getDefualt.syncExec

Causes the <code>run()</code> method of the runnable to be invoked by the user-interface thread at the next reasonable opportunity. The caller of this method continues to run in parallel, and is not notified when the runnable has completed.  Specifying <code>null</code> as the runnable simply wakes the user-interface thread when run.
Note that at the time the runnable is invoked, widgets that have the receiver as their display may have been disposed. Therefore, it is necessary to check for this case inside the runnable before accessing the widget.
Display.getDefault.asysnExec(Runnable)
Causes the <code>run()</code> method of the runnable to be invoked by the user-interface thread at the next reasonable opportunity. The thread which calls this method is suspended until the runnable completes.  Specifying <code>null</code> as the runnable simply wakes the user-interface thread.
Note that at the time the runnable is invoked, widgets that have the receiver as their display may have been disposed. Therefore, it is necessary to check for this case inside the runnable before accessing the widget.
Display.getDefault.sysnExec(Runnable)

posted @ 2008-02-13 11:25 Xiaobo Sun 阅读(516) | 评论 (0)编辑 收藏

# ps -aux|grep sysprocess

ps a 显示现行终端机下的所有程序,包括其他用户的程序。
2)ps -A 显示所有程序。
3)ps c 列出程序时,显示每个程序真正的指令名称,而不包含路径,参数或常驻服务的标示。
4)ps -e 此参数的效果和指定"A"参数相同。
5)ps e 列出程序时,显示每个程序所使用的环境变量。
6)ps f 用ASCII字符显示树状结构,表达程序间的相互关系。
7)ps -H 显示树状结构,表示程序间的相互关系。
8)ps -N 显示所有的程序,除了执行ps指令终端机下的程序之外。
9)ps s 采用程序信号的格式显示程序状况。
10)ps S 列出程序时,包括已中断的子程序资料。
11)ps -t  指定终端机编号,并列出属于该终端机的程序的状况。
12)ps u  以用户为主的格式来显示程序状况。
13)ps x  显示所有程序,不以终端机来区分。
最常用的方法是ps -aux,然后再利用一个管道符号导向到grep去查找特定的进程,然后再对特定的进程进行操作。

posted @ 2008-02-11 14:03 Xiaobo Sun 阅读(1048) | 评论 (1)编辑 收藏

Eclipse TCP/IP Monitoring

Eclipse TCP/IP Monitoring is a proxy service. This service runs on the "local monitoring port", and forwards the received message to the Monitor host/port. For example, this service runs on the localhost:7002, and forwards the message the localhost:3142.
LCT<-------(Localhost:3142<-Monitoring Service<-Localhost:7002)<---------MCU
The MCU request should be sent to localhost:7002, then redirect to localhost:3142 where the LCTCmdResponse service runs.
The LCT request should be sent to localhost:7001, then redirect to localhost:8080 where the LCTCmdIF service runs.

posted @ 2008-01-21 14:01 Xiaobo Sun 阅读(582) | 评论 (0)编辑 收藏

Eclipse Text Search

ctrl+h (to trigger the Search Wizard) -> go the file Tab -> type the text and search

posted @ 2008-01-17 14:18 Xiaobo Sun 阅读(214) | 评论 (0)编辑 收藏

仅列出标题
共7页: 上一页 1 2 3 4 5 6 7 下一页 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜