2013年3月13日
#
今天在做手機(jī)終端開(kāi)發(fā)時(shí),發(fā)現(xiàn)連上域名服務(wù)器老是連不上,而直接用IP連接是OK的,初步懷凝是DNS問(wèn)題引起來(lái),經(jīng)查相關(guān)的資料,現(xiàn)記錄如下:
Android模擬器默認(rèn)的地址是10.0.2.3,默認(rèn)的DNS也是10.0.2.3,而一般電腦的IP都是192.168.1.100之類(lèi)的,不在同一個(gè)網(wǎng)段。所以就會(huì)出現(xiàn)電腦可以上網(wǎng)但是模擬器不能上網(wǎng)的情況。其實(shí)設(shè)置方法很簡(jiǎn)單,只要把模擬器的默認(rèn)DNS設(shè)置成電腦的DNS地址即可。
第一步:用系統(tǒng)的命令進(jìn)入Android開(kāi)發(fā)包的tools目錄
cd X:\...\android-sdk-windows\tool
第二布:使用adb的shell,確認(rèn)系統(tǒng)的各項(xiàng)屬性
adb shell
getprop
getprop會(huì)列出系統(tǒng)當(dāng)前的各項(xiàng)屬性
第三步:得到模擬器的DNS地址
在結(jié)果里可以看到:
[net.dns1]: [10.0.2.3]
[net.dns2]: [10.0.2.4]
[net.dns3]: [10.0.2.5]
[net.dns4]: [10.0.2.6]
第四步:把dns改成我們自己的DNS
setprop net.dns1 192.168.1.1
連接的URL串
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=vip1)(PORT
=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vip2)(PORT=1521))(LOAD_BALANCE=yes)(FAILOVER=
on))(CONNECT_DATA=(SERVICE_NAME=gs)))
啟動(dòng) lsnrctl start
狀態(tài) lsnrctl status
關(guān)閉 lsnrctl stop
導(dǎo)出命令:exp 用戶(hù)名/密碼@數(shù)據(jù)庫(kù) owner=用戶(hù)名 file=文件存儲(chǔ)路徑(如:F:\abcd.dmp)
測(cè)試截圖:exp ZM/sql123@ORCL owner=ZM file=F\abcd.dmp
出.png)
導(dǎo)入命令:imp 用戶(hù)名/密碼@數(shù)據(jù)庫(kù) fromuser=用戶(hù)名 touser=用戶(hù)名 file=d:\cu.dmp ignore=y
imp:命令類(lèi)型
cu/mycu@db:導(dǎo)入的數(shù)據(jù)庫(kù)登陸(用戶(hù)名/密碼@數(shù)據(jù)庫(kù))
fromuser:文件的指定用戶(hù)
touser:指定導(dǎo)入到當(dāng)前登錄的數(shù)據(jù)庫(kù)某個(gè)用戶(hù)
file:需要導(dǎo)入的數(shù)據(jù)文件
ignore:是否忽略創(chuàng)建錯(cuò)誤
測(cè)試截圖:
imp ZM/sql123@ORCL fromuser=ZM touser=SZZM file=F:\test.dmp ignore=y
入.png)
linux環(huán)境下的rmi常見(jiàn)問(wèn)題
問(wèn)題一:RMI服務(wù)提供程序運(yùn)行在Windows操作系統(tǒng)下,RMI服務(wù)可以正常訪(fǎng)問(wèn),但將RMI服務(wù)提供程序部署到Linux操作系統(tǒng)下后,RMI服務(wù)無(wú)法訪(fǎng)問(wèn),提示
org.springframework.remoting.RemoteConnectFailureException:
Cannot connect to remote service [rmi://192.168.0.106:1199/ItemRetag]; nested exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; ……
解決辦法:在加載RMI服務(wù)之前將當(dāng)前服務(wù)器的IP指定給hostName,如 System.setProperty("java.rmi.server.hostname", "192.168.100.7");或者修改/etc/hosts文件,在這個(gè)文件中加 192.168.100.54 testlinux1 localhost.localdomain localhost 就行,或者將/etc/hosts文件中默認(rèn)的127.0.0.1改成當(dāng)前機(jī)器的IP即可!
問(wèn)題二:java.rmi.server.ExportException: internal error: ObjID already in use Caused by: java.rmi.server.ExportException: internal error: ObjID already in use……
出現(xiàn)這種問(wèn)題及有可能是/etc/hosts文件中指定的IP并不是當(dāng)前服務(wù)器的真實(shí)IP,RMI在初始化時(shí)注冊(cè)服務(wù)失敗。
通過(guò)System.out.println(InetAddress.getLocalHost().toString());查看當(dāng)前主機(jī)的IP是否為真實(shí)IP,如顯示為SIMBANK/220.250.64.24,而真實(shí)IP為192.168.1.2
解決辦法:修改/etc/hosts文件中錯(cuò)誤的IP即可,將:
220.250.64.24 SIMBANK
修改為
192.168.1.2 SIMBANK
JAVA中,通過(guò)分析Heapdump文件可以檢查程序是否存在內(nèi)存泄露,但是這個(gè)文件一般是在程序遇到致命問(wèn)題時(shí)才會(huì)產(chǎn)生,而如何事前生成這個(gè)文件,從而在程序尚末崩潰前找出問(wèn)題的所在。
以下記述了各個(gè)版本的JDK產(chǎn)生DUMP文件的方法:
UN JDK生成Heapdump文件只需要在tomcat啟動(dòng)腳本中增加 HeapDumpOnOutOfMemoryError 參數(shù)
此參數(shù)需要Java SE release 5.0 update 14 或以上支持
設(shè)置示例:
set JAVA_OPTS=%JAVA_OPTS% -server -Xms512m -Xmx800m -XX:PermSize=64M -XX:MaxPermSize=128m -Djava.awt.headless=true -XX:+HeapDumpOnOutOfMemoryError -XX:+HeapDumpOnCtrlBreak
IBM JDK生成Heapdump文件的開(kāi)關(guān):
— export IBM_HEAPDUMP=true
— export IBM_HEAP_DUMP=true
— export IBM_HEAPDUMP_OUTOFMEMORY=true
— export IBM_JAVADUMP_OUTOFMEMORY=true
— export IBM_JAVACORE_OUTOFMEMORY=true
— export IBM_HEAPDUMPDIR=<directory_path>
HP JDK生成Heapdump文件需要在在環(huán)境變量上,加上export _JAVA_HEAPDUMP=1
今天在做某項(xiàng)目的POC測(cè)試,甲方提供了一個(gè)三十萬(wàn)記錄的TXT數(shù)據(jù)文件,需要把該文件的記錄插入到數(shù)據(jù)庫(kù)中,由于項(xiàng)目部的同事在搭建測(cè)試環(huán)境中用的是Mysql數(shù)據(jù)庫(kù),在把數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)中用的是JDBC的批處理。代碼如下

private void batchParseGroup()
{
Connection con= null;
PreparedStatement ps =null;

try
{
con= DbConnectionManager.getConnection();
con.setAutoCommit(false);
String sql = " insert into jivegroup(uri,groupname,pgroupid,description,creationdate,modificationdate,priority,selfpriority) values(?,?,?,?,?,?,?,?)";
ps= con.prepareStatement(sql);

for(int i=0;i<groupList.size();i++)
{
Group group = groupList.get(i);
ps.setString(1, group.getUri());
ps.setString(2, group.getName());
ps.setString(3, group.getPgroupId());
ps.setString(4, group.getName());
ps.setString(5, ""+System.currentTimeMillis());
ps.setString(6, ""+System.currentTimeMillis());
ps.setInt(7, group.getPriority());
ps.setInt(8, group.getPriority());
ps.addBatch();

if(i%100==0)
{
ps.executeBatch();
}
}
con.commit();
ps.executeBatch();

} catch (SQLException e)
{
e.printStackTrace();

}finally
{
DbConnectionManager.closeConnection(ps, con);
}
}在測(cè)試時(shí),發(fā)現(xiàn)三十萬(wàn)的數(shù)據(jù)居然需要十分鐘左右的時(shí)間。首先想到的就是Mysql的相關(guān)配置是不是有問(wèn)題,反復(fù)修改了Mysql的相應(yīng)配置參數(shù),收效甚微。
在Mysql的官網(wǎng)上查到如下:
http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-configuration-properties.html
關(guān)于rewriteBatchedStatements參數(shù),Mysql官方的說(shuō)明:
Should the driver use multiqueries (irregardless of the setting of "allowMultiQueries") as well as rewriting of prepared statements for INSERT into multi-value inserts when executeBatch() is called? Notice that this has the potential for SQL injection if using plain java.sql.Statements and your code doesn't sanitize input correctly. Notice that for prepared statements, server-side prepared statements can not currently take advantage of this rewrite option, and that if you don't specify stream lengths when using PreparedStatement.set*Stream(), the driver won't be able to determine the optimum number of parameters per batch and you might receive an error from the driver that the resultant packet is too large. Statement.getGeneratedKeys() for these rewritten statements only works when the entire batch includes INSERT statements.
解決辦法:
下載最新的JDBC的驅(qū)動(dòng)程序。
MYSQL URL的配置參數(shù)如下:
jdbc:mysql://54.200.190.80:3306/ccb_ucstar?rewriteBatchedStatements=true
經(jīng)過(guò)測(cè)試。三十多萬(wàn)的數(shù)據(jù)。70秒內(nèi)搞定!