能帮忙java架构师学习路线java的博主

1104人阅读
java web开发(3)
由于项目需要需要开发web程序,于是在网上查找web开发的相关技术主要是:windows下asp+iis+Visual Studio。可以跨平台的是java web(jsp)技术和php技术。由于跨平台的需求asp直接否掉。java(jsp)技术和php技术各有优劣势。但是考虑到java是完成的解决方案,php只是用于网站开发,并且java对各种设计模式的支持要好一些,回头如果需要可转化为php+jsp,比php转jsp要容易,故选择了java(jsp)作为主要的开发技术。
技术方案选择完毕,接下来就是配置开发环境。网上主要有两派eclipse jee和myeclipse。可参考这篇文章来选择。最终我选择使用eclipse
jee作为开发环境。这是因为可以多倒腾一下,并且环境干净,容易看到问题的本质。对提高有好处。下载tomcat和eclipse jee版本后。参考这篇文章来做第一个程序helloworld,。在这篇文章中当运行程序时弹出的run
on server对话框(如下)实际上就是创建server的过程,可参考中的创建srever过程,来知其然且知其所以然。注意其中的Context&root:和创建servlet时的url
mappings:这两个变量构成访问servlet的标示http://localhost:8080/Context root/Url mappings。
如何将myeclipse dynamic web工程转换为eclipse jee dynamic web工程?
由于myeclipse和eclipse一脉相承,故myeclipse转换为eclipse工程比较 容易。
首先将myeclipse的src下的源码复制到eclipse工程下的src下,其他的源码也复制到src下(也可以不复制到src下,直接复制到工程文件夹下然后添加Properties-&Java Build Path-&Source)。
然后将WebRoot下的内容复制WebContent下。
最终生成的网站内容WEB-INF/classes下的一些配置文件是由eclipse jee工程的src下的文件生成的,例如struts.xml, log4j.xml等,故可以把myeclipse工程生成在WEB-INF/classes下的配置文件都复制到eclipse jee工程的src下,即可。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:103405次
积分:1435
积分:1435
排名:第19151名
原创:40篇
评论:18条
(1)(2)(7)(5)(1)(7)(1)(14)(1)(1)(1)(2)(2)(2)软件,还是开源的好
追梦,不轻言放弃!
善于利用工具,不仅可以加快我们分析数据,还可以快速定位和解决问题。现在我们就来看看虚拟机性能监控和故障处理工具。
在JDK的bin目录可以看到sun免费送给了我们很多小工具,这些工具虽然小巧但功能强大且稳定,你看到的小工具其实是lib\tools.jar的快捷方式而已,工具的具体执行是被打包进了tools.jar了。
jps:虚拟机进程状态工具(JVM Process Status Tool)
jps不仅名字像unix的ps命令,其功能与ps也很类似:列出正在运行的虚拟机进程,并显示虚拟机执行主类(main()所在的类)的名字,以及这些进程再本地虚拟机的唯一ID(LVMID,Local Virtual Machine Identifier)。而LVMID和操作下图的PID(Process Identifier)是一致的。如果同时启动了多个虚拟机进程,无法根据进程名称定位时,那就只能依赖jps命令显示主类的功能区分了。命令格式:
usage: jps [-help]
jps [-q] [-mlvV] [&hostid&]
Definitions:
&hostname&[:&port&]
-q 仅输出LVMID,省略主类的名称;
-m 输出虚拟机进程启动时传递给主类main()函数的参数;
-l 输出主类的全名,如果进程执行的是jar包,则输出jar的路径;
-v 输出虚拟机进程启动时JVM参数;
-V 输出通过flag文件传递到JVM中的参数;
-Joption 传递参数到JVM,例如:-J-Xms48m;
hostid的格式是:&hostname&[:&port&],port默认是1099,需要服务器启动jstatd服务,否则会提示
RMI Server JStatRemoteHost not available
jstatd命令是一个RMI Server应用程序,提供了对JVM的创建和结束监视,也为远程监视工具提供了一个可以attach的接口。用法
usage: jstatd [-nr] [-p port] [-n rminame]
-nr 当一个存在的RMI Registry没有找到时,不尝试创建一个内部的RMI Registry;
-p port 端口号,默认为1099;
-n rminame 默认为JStatRemoteHost;如果多个jstatd服务开始在同一台主机上,rminame唯一确定一个jstatd服务;
-J jvm选项;
在服务器直接启动jstatd会报如下异常
Could not create remote object
access denied (java.util.PropertyPermission java.rmi.server.ignoreSubClasses write)
java.security.AccessControlException: access denied (java.util.PropertyPermission java.rmi.server.ignoreSubClasses write)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.System.setProperty(System.java:727)
at sun.tools.jstatd.Jstatd.main(Jstatd.java:122)
这是因为没有给jstatd指定安全策略,需要创建安全策略文件,自定义命名为java.all.policy,内容如下:
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllP
jstatd -J-Djava.security.policy=java.all.policy
或使用自定义端口2020
rmiregistry 2020&
jstatd -J-Djava.security.policy=java.all.policy -p 2020
注意要指定java.all.policy文件的路径。
然后可以使用jps连接
jps 10.9.146.201
jps rmi://10.9.146.201:1099
jstat:虚拟机统计信息监视工具(JVM Statistics Monitoring Tool)
Jstat主要用于监控虚拟机的各种运行状态信息,如类的装载、内存、垃圾回收、JIT编译器等,在没有GUI的服务器上,这款工具是首选的一款监控工具。其用法如下:
jstat [option vmid [interval [s|ms] [vount] ] ]
如果是在本地虚拟机进程,vmid与lvmid是一致的,如果是远程虚拟机进程,那么vmid的格式是:[protocol:][//]lvmid[@hostname[:port]/servername]
参数interval和count分别表示查询间隔和查询次数,如每1毫秒查询一次进程20445的垃圾回收情况,监控20次,命令如下所示:
jstat –gc
选项option代表用户需要查询的虚拟机的信息,主要分为3类:类装载、垃圾回收和运行期的编译情况,具体如下表所示:
监视类的装载、卸载数量以及类的装载总空间和耗费时间等
监视Java堆,包含eden、2个survivor区、old区和永久带区域的容量、已用空间、GC时间合计等信息
-gccapcity
监视内容与-gc相同,但输出主要关注Java区域用到的最大和最小空间
监视内容与-gc相同,但输出主要关注已使用空间占总空间的百分比
与-gcutil输出信息相同,额外输出导致上次GC产生的原因
监控新生代的GC情况
-gcnewcapacity
与-gcnew监控信息相同,输出主要关注使用到的最大和最小空间
监控老生代的GC情况
-gcoldcapacity
与-gcold监控信息相同,输出主要关注使用到的最大和最小空间
-gcpermcapacity
输出永久带用到的最大和最小空间
输出JIT编译器编译过的方法、耗时信息
-printcompilation
输出已经被JIT编译的方法
jinfo:Java配置信息工具(Configuration Info for Java)
jinfo的作用是实时查看和调整虚拟机的各项参数,但其在windows上好多选项不能用的,用法:
jinfo [option] &pid&
(to connect to running process)
jinfo [option] &executable &core&
(to connect to a core file)
jinfo [option] [server_id@]&remote server IP or hostname&
(to connect to remote debug server)
where &option& is one of:
-flag &name&
to print the value of the named VM flag
-flag [+|-]&name&
to enable or disable the named VM flag
-flag &name&=&value& to set the named VM flag to the given value
to print VM flags
to print Java system properties
&no option&
to print both of the above
-h | -help
to print this help message
jmap:Java内存映像工具(Memory Map for Java)
jmap不仅用于生成堆转储快照,还可以查询finalize执行队列、Java堆和永久代的详细信息,如空间使用率、当前用的是哪种收集器等。和jinfo一样,jmap有不少功能在Windows平台下都是受限的。用法
jmap [option] &pid&
(to connect to running process)
jmap [option] &executable &core&
(to connect to a core file)
jmap [option] [server_id@]&remote server IP or hostname&
(to connect to remote debug server)
主要选项如下
-dump:生成Java堆转储快照。格式为:-dump:[live,] format=b,file=&filename&,其中live子参数说明是否只dump出存活的对象
-finalizerinfo:显示在F-Queue中等待Finalizer线程执行finalize方法的对象。只在Linux/Solaris平台下有效。
-heap:显示Java堆详细信息,如使用哪种收集器、参数配置、分代状况等。只在Linux/Solaris平台下有效。
-histo:显示堆中对象统计信息,包括类、实例数量和合计容量。
-permstat:以ClassLoader为统计口径显示永久代内存状态。只在Linux/Solaris平台下有效。
-F:当虚拟机进程对-dump选项没有响应时,可以使用这个选项强制生成dump快照。只在Linux/Solaris平台下有效。
jhat:虚拟机堆转储快照分析工具(JVM Heap Analysis Tool)
jhat命令与jmap命令搭配使用,来分析jmap生成的堆存储快照。jhat内置了一个微型的HTTP/HTML服务器,生成dump文件的分析结果后,可以在浏览器中查看。实事求是地说,不过一般不会使用如此简陋的工具来分析dump文件。
jstack:Java堆栈跟踪工具(Stack Trace for Java)
jstack命令用于生成虚拟机当前时刻的线程快照(一般称为threaddump或javacore文件)。线程快照就是当前虚拟机内每一条线程正在执行的方法的堆栈的机会,生成线程快照的主要目的是定位线程出现长时间停顿的原因,如线程间死锁、死循环、请求外部资源导致的长时间等待等都是导致线程长时间停顿的常见原因。线程出现停顿的时候通过jstack来查看各个线程的调用堆栈,就可以知道没有响应的线程到底在后台做些什么事情,或者等待着什么资源。
jstack命令格式:
jstack [ option ] vmid
option选项的合法值与具体含义为:
-F : 当正常输出的请求不被响应时,强制输出线程堆栈;
-l:除堆栈外,显示关于锁的附加信息;
-m:如果调用到本地方法的话,可以显示C/C++的堆栈;
以上都是小工具,还有非常齐全的整合工具如jconsole和VisualVM,都是非常强的工具,而是jconsole的增强版,使用VisualVM链接远程也需要启动jstatd服务,具体就不详述了。
>> 博主下一篇:
<< 博主上一篇:Hadoop(20)
有用到通过java client或者python client操作HDFS,记录一下简单的代码片段。
WebHDFS的认证方式
WebHDFS的认证方式有三种:
Authentication
When security is off, the authenticated user is the username specified in the user.name query parameter. If the user.name parameter is not set, the server may either set the authenticated user to a default web user, if there is any, or return an error response.
When security is on, authentication is performed by either Hadoop delegation token or Kerberos SPNEGO. If a token is set in the delegation query parameter, the authenticated user is the user encoded in the token. If the delegation parameter is not set, the user is authenticated by Kerberos SPNEGO.
Below are examples using the curl command tool.
Authentication when security is off:
curl -i “http://:/webhdfs/v1/?[user.name=&]op=…”
Authentication using Kerberos SPNEGO when security is on:
curl -i –negotiate -u : “http://:/webhdfs/v1/?op=…”
Authentication using Hadoop delegation token when security is on:
curl -i “http://:/webhdfs/v1/?delegation=&op=…”
Java访问WebHDFS
这里没有开启安全认证。
测试的REST API:
代码片段:
import java.io.BufferedR
import java.io.IOE
import java.io.InputS
import java.io.InputStreamR
import java.net.HttpURLC
import java.net.MalformedURLE
import java.net.URL;
import java.sql.T
import java.text.MessageF
import java.util.ArrayL
import java.util.L
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONO
* &b&LISTSTATUS&/b&
* curl -i "http://&HOST&:&PORT&/webhdfs/v1/&PATH&?op=LISTSTATUS&user.name=hdfs"
* totalDir
* IOException
public List&String& getHDFSDirs(String totalDir, String host, String port) throws IOException {
String httpfsUrl = BackupUtils.DEFAULT_PROTOCOL + host + ":" +
String spec = MessageFormat.format("/webhdfs/v1{0}?op=LISTSTATUS&user.name={1}", totalDir, "hdfs");
URL url = new URL(new URL(httpfsUrl), spec);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
String resp = result(conn, true);
conn.disconnect();
JSONObject root = JSON.parseObject(resp);
int size = root.getJSONObject("FileStatuses").getJSONArray("FileStatus").size();
List&String& dirs = new ArrayList&&();
for(int i = 0; i & ++i) {
String dir = root.getJSONObject("FileStatuses").getJSONArray("FileStatus").getJSONObject(i).getString("pathSuffix");
dirs.add(dir);
* Report the result in STRING way
* IOException
public String result(HttpURLConnection conn, boolean input) throws IOException {
StringBuffer sb = new StringBuffer();
if (input) {
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"));
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
reader.close();
is.close();
return sb.toString();
Python访问WebHDFS
同样也没有开启安全认证。
测试的REST API:
代码片段:
agent_config = AmbariConfig()
WEBHDFS_CONTEXT_ROOT="/webhdfs/v1"
class WebHDFS(object):
""" Class for accessing HDFS via WebHDFS
To enable WebHDFS in your Hadoop Installation add the following configuration
to your hdfs_site.xml (requires Hadoop &0.20.205.0):
&property&
&name&dfs.webhdfs.enabled&/name&
&value&true&/value&
&/property&
def __init__(self, namenode_host, namenode_port, hdfs_username):
self.namenode_host=namenode_host
self.namenode_port = namenode_port
self.username = hdfs_username
def __getNameNodeHTTPClient(self):
httpClient = httplib.HTTPConnection(self.namenode_host,
self.namenode_port,
timeout=600)
return httpClient
def listdir(self, path):
if os.path.isabs(path)==False:
raise Exception("Only absolute paths supported: %s"%(path))
url_path = WEBHDFS_CONTEXT_ROOT + path+'?op=LISTSTATUS&user.name='+self.username
httpClient = self.__getNameNodeHTTPClient()
httpClient.request('GET', url_path, headers={})
response = httpClient.getresponse()
data_dict = json.loads(response.read())
files = []
for i in data_dict["FileStatuses"]["FileStatus"]:
files.append(i["pathSuffix"])
httpClient.close()
return files
webhdfs = WebHDFS(namenode_host, int(namenode_http_port), "hdfs")
source_files = webhdfs.listdir(source)
Reference:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:335985次
积分:7344
积分:7344
排名:第1793名
原创:442篇
转载:52篇
评论:75条
(4)(6)(5)(5)(14)(2)(53)(28)(28)(8)(35)(23)(48)(71)(9)(10)(20)(6)(5)(5)(17)(32)(7)(5)(15)(8)(6)(1)(3)(2)(1)(2)(1)(1)(9)11:57 提问
刚开始学习java ,自己写了一个聊天小程序,没报错但是有毛病,希望能帮忙问一下
刚开始学习java ,自己写了一个聊天小程序,没有报任何错误。测试时打开3个聊天小窗口 A,B,C,在A中输入文字,只在B中显示出来了,而且显示出了三句相同语句。查了好几个小时都没有查出来,希望高手能帮帮忙,看看是怎么回事,并且告诉我是通过什么方法找出来的。
以下是客户端和服务器端代码
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class MyChatClient extends Frame {
* @param args
//设置窗口位置及大小
private static final int CHAT_LAYOUT_X = 300;
private static final int CHAT_LAYOUT_Y = 100;
private static final int CHAR_SIZE_X =500;
private static final int CHAR_SIZE_Y =500;
//设置文本框和文本域
private TextA
private TextF
private DataInputStream dis =
private DataOutputStream dos =
private String message = "";
private boolean flag =
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyChatClient().MyChatFrame();
//设置聊天室框架及基本相应事件
public void MyChatFrame(){
this.setTitle("聊天室");
this.setLocation(CHAT_LAYOUT_X,CHAT_LAYOUT_Y);
this.setSize(CHAR_SIZE_X,CHAR_SIZE_Y);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
disConnection();
System.exit(0);
ta = new TextArea();
tf = new TextField();
this.add(ta,BorderLayout.NORTH);
this.add(tf,BorderLayout.SOUTH);
this.pack();
TfEvent te = new TfEvent();
tf.addActionListener(te);
this.setVisible(true);
connecter();
new Thread(new ReadThread()).start();
class TfEvent implements ActionListener{
public void actionPerformed(ActionEvent e){
String str = tf.getText();
ta.setText(ta.getText()+str+'\n');
tf.setText("");
dos.writeUTF(str);
dos.flush();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
//连接服务器
public void connecter() {
s = new Socket("127.0.0.1",6666);
dis = new DataInputStream(s.getInputStream());
dos = new DataOutputStream(s.getOutputStream());
//new Thread(new ReadThread()).start();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
private class ReadThread implements Runnable{
public void run(){
while(flag){
message = dis.readUTF();
ta.setText(ta.getText()+message+'\n');
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
private void disConnection(){
if(dis!=null){dis.close();dis=}
if(dos!=null){dos.close(); dos=}
if(s!=null){s.close(); s=}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
服务器端:
import java.net.*;
import java.util.ArrayL
import java.util.L
import java.io.*;
public class MyChatServer {
private boolean bConnection =
private boolean flag =
private ServerSocket ss =
private Socket s =
private DataInputS
private DataOutputS
private List clients = new ArrayList();
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyChatServer().myChat();
public void myChat(){
ss =new ServerSocket(6666);
bConnection =
while(bConnection){
s = ss.accept();
ChatClient cc = new ChatClient(s);
clients.add(cc);
new Thread(cc).start();
}catch(IOException
e.printStackTrace();
//处理客户信息内部类
class ChatClient implements Runnable{
Socket so =
public ChatClient(Socket s){
dis = new DataInputStream(so.getInputStream());
dos = new DataOutputStream(so.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public void run(){
while(flag){
message = dis.readUTF();
for(int i=0; i&clients.size(); i++){
ChatClient c = clients.get(i);
c.send(message);
} catch (IOException e) {
e.printStackTrace();
if(dis!=null){dis.close(); dis=}
if(dos!=null){dos.close(); dos=}
if(s!=null){s.close(); s=}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public void send(String str){
dos.writeUTF(str);
dos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
按赞数排序
你用到了继承和接口,父类的输出可能被子类给覆盖了,你调试的时候仔细看看是不是这方法的问题;
使用debug调试一下嘛!很容易检查出来错误的!最好发下错误消息...
设计一个断点来查看一下在哪里出错了。。。
调试一下,认为还是处在你的方法错误》
10523关注|454收录
10845关注|1078收录
2375关注|618收录
其他相似问题
相关参考资料

我要回帖

更多关于 java学习 的文章

 

随机推荐