advance programming期末复习

主要是课件上需要记忆的,还有空手写代码时的小细节。考前串一下。

week1 thread

thread 的概念:Thread is a lightweight process which has its own cache, can run and share data with other threads.

2 ways to creat thread.

1).Extend thread. e.g.Thread t=new thread(); trigger default contributor with no argument to run.

2).implement Runnable interface, and creat new thread.

start()和run()的区别:

When start() is invoked, the thread goes into ready status, which means it is eligble for running. Excution of the thread starts when run() method is called by JVM.

3 way terminate thread: 不写了 课件上有

Synchronized 和volatile的区别:

only primitive variable can be declared as volatile; volatile cannot protect complex codes; Access to volatile variable cannot has the potential to be protected.

Entry set&Wait set

When a thread wants to access to a block of code protected by synchronized, but it doesn't have the lock, it is in entry set.

When it get the lock, but other threads are excuting that code, the thread needs to enter wait set by callng the wait() method. And this thread will stay in wait() until notify().

lock&read write lock:

lock means only one thread can be permitted to excute this block of code, but sometime it is slow. Read write lock permits more readers at the same time and only one writer.

Synchronized 3种作用范围:

1.synchronized method 2.括号里加some objects 3. an object can use itself as a lock e.g.synchronized(this)

week 1 socket

概念:creat connection to remote computers to receive and send data.

空手写代码:server端和client端

【注】都要import java.net.*; import java.io.*;

都要bufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream()));

PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),true)));       //可以说是巨难背了

server端:有一个变量 public static final int PORT=8080;

有两个try

client端:InetAddress addr=InetAddress.getByName(127.0.0.1);

如果要multiple clients 就写个while loop 里 s.accept();

week 2

Serializable

import java.io.*; serializable is marker interface, no method to implement.

OutputStream outputFile=new FileOutputStream("....ser");

ObjectOutputStream cout=new ObjectOutputStream(outputFile);

outputFile.writeObject(object);

最后加两个close().

RMI

概念:send java objects and invoke methods form remote computer.

主要4部分: interface,impl, server, client

interface: import java.rmi.remote; 因为它要extends Remote.

impl: import java.rmi.*; import java.rmi.server.*; 然后extends UnicastRemoteObject implement interface.

server和client都import java.rmi.naming;

Stub和Skeleton的作用

Stub 3点

1)Implement same interface as server; 2)serialize argument to call the remote method and send to server; 3)receive and deserialize the result

Skeleton 4点

1)Receive the remote call of method 2)deserialize the parameters; 3)find a suitable method on behalf of remote client 4)serilaize and send back the result to client

RMI registry: a program that keeps mapping of remote object interfaces.

HTTP

HTTP request response header会画

TCP 结构图

...



week 3,week 4还没整理完就考试了, 就酱吧~

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 137,249评论 19赞 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 35,313评论 18赞 399
  • 文\过境蝴蝶 一个同事出差前给我共享了他电脑里70个G的电影片库,我在里面找到了这部《七磅》,在看它之前完全没有接...
    断翅蝴蝶阅读 2,617评论 5赞 11
  • 一个长寿村在苏有朋饰演的牛医生的蛊惑下设计了一场迷惑人神经的杀人案。我看影片,感觉最吸引人之处,是从头至尾似是而非...
    梧桐断角阅读 301评论 0赞 2
  • 以前总觉得友谊地久天长,以为认识一个人就会是一辈子。 原来真的会有很多渐行渐远的感情,人真的是个很奇怪的生物,因为...
    邓冰是我女神阅读 612评论 0赞 0

友情链接更多精彩内容