Shared Folders是Vmware4
的一個新功能,更加方便了在Host,Guest操作系統(tǒng)間共享文件。它是把Host機器上的一個目錄共享給Guest機器使用。點擊Edit-
>;Virtual machine settigns->;Option->;Shared
Folders->;Add,選定要共享的文件夾并給這個文件夾命名,下一步。選定“Enable this
share”,還有只讀和重啟后失效的選項,根據需要選擇。
確定以后,vmware會把這個文件夾自動mount到/mnt/hgfs目錄下
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.
Thread is the 進程, Runnable is the 進程對象
[第一需要弄清的問題]
如同程序和進程的區(qū)別,要掌握多線程編程,第一要弄清的問題是:線程對象和線程的區(qū)別。
線程對象是可以產生線程的對象。比如在java平臺中Thread對象,Runnable對象。線程,是指正在執(zhí)行的一個指點令序列。在java平臺上是指從一個線程對象的start()開始,運行run方法體中的那一段相對獨立的過程。
鑒于作者的水平,無法用更確切的詞匯來描述它們的定義。但這兩個有本質區(qū)別的概念請初學者細細體會,隨著介紹的深入和例程分析的增加,就會慢慢明白它們所代表的真實含義。
天下難事必始于易,天下大事必始于細。
讓我們先從最簡單的"單線程"來入手:(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
現在發(fā)生了什么呢?每一個java程序員,從他開始學習java的第一分鐘里都會接觸到這個問
題,但是,你知道它到底發(fā)生發(fā)什么?
JVM進程被啟動,在同一個JVM進程中,有且只有一個進程,就是它自己。然后在這個JVM環(huán)境中,所有程序的運行都是以線程來運行。JVM最先會產生
一個主線程,由它來運行指定程序的入口點。在這個程序中,就是主線程從main方法開始運行。當main方法結束后,主線程運行完成。JVM進程也隨之退
出。
我們看到的是一個主線程在運行main方法,這樣的只有一個線程執(zhí)行程序邏輯的流程我們稱
之為單線程。這是JVM提供給我們的單線程環(huán)境,事實上,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");
}
}
執(zhí)行這個程序,main方法第一行產生了一個線程對象,但并沒有線程啟動。
main方法第二行產生了一個線程對象,并啟動了一個線程。
main方法第三行,產生并啟動一個線程后,主線程自己也繼續(xù)執(zhí)行其它語句。
我們先不研究Thread對象的具體內容,稍微來回想一下上面的兩個概念,線程對象和線程。在JAVA中,線程對象是JVM產生的一個普通的Object子類。而線程是CPU分配給這個對象的一個運行過程。我們說的這個線程在干什么,不是說一個線程對象在干什么,而是這個運行過程在干什么。如果一時想不明白,不要急,但你要記得它們不是一回事就行了。
現在我們來開始考察JAVA中線程對象。
在JAVA中,要開始一個線程,有兩種方式。一是直接調用Thread實例的start()方法,二是
將Runable實例傳給一個Thread實例然后調用它的start()方法。
在前面已經說過,線程對象和線程是兩個完全不同的概念。這里我們再次深入一下,生成一個線程的實例,并不代表啟動了線程。而啟動線程是說在某個線程對象上啟動了該實例對應的線程,當該線程結束后,并不會就立即消失。
對于從很多書籍上可以看到的基礎知識我就不用多說了。既然是基礎知識,我也著重于從普通文檔上讀不到的內容。所以本節(jié)我重點要說的是兩種線程對象產生線程方式的區(qū)別。
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()方法,就是讓當前正在執(zhí)行的線程等待線程對象a對應的線程運行
完成后才繼續(xù)運行。" 請大家一定要深刻理解并熟記這句話,而我這里引出這個知識點的目的是為了讓你繼續(xù)看下面的例子:
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,事實中不管這個線程后來有沒有執(zhí)行到底,只要調用了一次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()沒有什么區(qū)別。但如果我們把一個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上運行的,所以沒
有對多個線程同時操作共同的對象進行同步。這里是為了說明的方便而簡化了同步,而真正的環(huán)境中你無法預知程序會在什么環(huán)境下運行,所以一定要考慮同步。
到這里我們做一個完整的例子來說明線程產生的方式不同而生成的線程的區(qū)別:
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實例)的多個線程。
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)
ps a 顯示現行終端機下的所有程序,包括其他用戶的程序。
2)ps -A 顯示所有程序。
3)ps c 列出程序時,顯示每個程序真正的指令名稱,而不包含路徑,參數或常駐服務的標示。
4)ps -e 此參數的效果和指定"A"參數相同。
5)ps e 列出程序時,顯示每個程序所使用的環(huán)境變量。
6)ps f 用ASCII字符顯示樹狀結構,表達程序間的相互關系。
7)ps -H 顯示樹狀結構,表示程序間的相互關系。
8)ps -N 顯示所有的程序,除了執(zhí)行ps指令終端機下的程序之外。
9)ps s 采用程序信號的格式顯示程序狀況。
10)ps S 列出程序時,包括已中斷的子程序資料。
11)ps -t 指定終端機編號,并列出屬于該終端機的程序的狀況。
12)ps u 以用戶為主的格式來顯示程序狀況。
13)ps x 顯示所有程序,不以終端機來區(qū)分。
最常用的方法是ps -aux,然后再利用一個管道符號導向到grep去查找特定的進程,然后再對特定的進程進行操作。
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.