解决方法:
<appSettings>
<add key="disableLuceneLocks" value="true" />
</appSettings>
在配置文件中加入这句就可以解决问题了。
from:http://www.oschina.net/question/1859_23187
这年头找个正经能用的东西那是真难,网上一搜索一大堆,正经能用的没几个,得,最后还是得靠自己,正巧遇上需要AES加解密的地方了,而且还是Java和C#间的相互加解密操作,这里做个备忘 这里采用的加解密使用base64转码方法,ECB模式,PKCS5Padding填充,密码必须是16位,否则会报错哈 模式:Java的ECB对应C#的System.Security.Cryptography.CipherMode.ECB 填充方法:Java的PKCS5Padding对应C#System.Security.Cryptography.PaddingMode.PKCS7 Java和C#版的加解密是互通的,也就是能相互加解密,编码明确指定了采用UTF-8,有需要其他编码方法的请自行扩展 Java版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
package nb.tmall.util; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import sun.misc.*; @SuppressWarnings("restriction") public class EncryptUtil { public static String aesEncrypt(String str, String key) throws Exception { if (str == null || key == null) return null; Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES")); byte[] bytes = cipher.doFinal(str.getBytes("utf-8")); return new BASE64Encoder().encode(bytes); } public static String aesDecrypt(String str, String key) throws Exception { if (str == null || key == null) return null; Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES")); byte[] bytes = new BASE64Decoder().decodeBuffer(str); bytes = cipher.doFinal(bytes); return new String(bytes, "utf-8"); } } |
C#版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using System; using System.Security.Cryptography; using System.Text; namespace CSharp.Util.Security { /// <summary> /// AES 加密 /// </summary> /// <param name="str"></param> /// <param name="key"></param> /// <returns></returns> public static string AesEncrypt(string str, string key) { if (string.IsNullOrEmpty(str)) return null; Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str); System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged { Key = Encoding.UTF8.GetBytes(key), Mode = System.Security.Cryptography.CipherMode.ECB, Padding = System.Security.Cryptography.PaddingMode.PKCS7 }; System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor(); Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Convert.ToBase64String(resultArray, 0, resultArray.Length); } /// <summary> /// AES 解密 /// </summary> /// <param name="str"></param> /// <param name="key"></param> /// <returns></returns> public static string AesDecrypt(string str, string key) { if (string.IsNullOrEmpty(str)) return null; Byte[] toEncryptArray = Convert.FromBase64String(str); System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged { Key = Encoding.UTF8.GetBytes(key), Mode = System.Security.Cryptography.CipherMode.ECB, Padding = System.Security.Cryptography.PaddingMode.PKCS7 }; System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor(); Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Encoding.UTF8.GetString(resultArray); } } } |
from:http://www.cnblogs.com/lzrabbit/p/3639503.html
View DetailsAES指高级加密标准(Advanced Encryption Standard),是当前最流行的一种密码算法,在web应用开发,特别是对外提供接口时经常会用到,下面是我整理的一套php与java通用的AES加密解密算法。 php版代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
<?php class CryptAES { protected $cipher = MCRYPT_RIJNDAEL_128; protected $mode = MCRYPT_MODE_ECB; protected $pad_method = NULL; protected $secret_key = ''; protected $iv = ''; public function set_cipher($cipher) { $this->cipher = $cipher; } public function set_mode($mode) { $this->mode = $mode; } public function set_iv($iv) { $this->iv = $iv; } public function set_key($key) { $this->secret_key = $key; } public function require_pkcs5() { $this->pad_method = 'pkcs5'; } protected function pad_or_unpad($str, $ext) { if ( is_null($this->pad_method) ) { return $str; } else { $func_name = __CLASS__ . '::' . $this->pad_method . '_' . $ext . 'pad'; if ( is_callable($func_name) ) { $size = mcrypt_get_block_size($this->cipher, $this->mode); return call_user_func($func_name, $str, $size); } } return $str; } protected function pad($str) { return $this->pad_or_unpad($str, ''); } protected function unpad($str) { return $this->pad_or_unpad($str, 'un'); } public function encrypt($str) { $str = $this->pad($str); $td = mcrypt_module_open($this->cipher, '', $this->mode, ''); if ( empty($this->iv) ) { $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); } else { $iv = $this->iv; } mcrypt_generic_init($td, $this->secret_key, $iv); $cyper_text = mcrypt_generic($td, $str); $rt=base64_encode($cyper_text); //$rt = bin2hex($cyper_text); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $rt; } public function decrypt($str){ $td = mcrypt_module_open($this->cipher, '', $this->mode, ''); if ( empty($this->iv) ) { $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); } else { $iv = $this->iv; } mcrypt_generic_init($td, $this->secret_key, $iv); //$decrypted_text = mdecrypt_generic($td, self::hex2bin($str)); $decrypted_text = mdecrypt_generic($td, base64_decode($str)); $rt = $decrypted_text; mcrypt_generic_deinit($td); mcrypt_module_close($td); return $this->unpad($rt); } public static function hex2bin($hexdata) { $bindata = ''; $length = strlen($hexdata); for ($i=0; $i amp;< $length; $i += 2) { $bindata .= chr(hexdec(substr($hexdata, $i, 2))); } return $bindata; } public static function pkcs5_pad($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); return $text . str_repeat(chr($pad), $pad); } public static function pkcs5_unpad($text) { $pad = ord($text{strlen($text) - 1}); if ($pad > strlen($text)) return false; if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false; return substr($text, 0, -1 * $pad); } } $keyStr = 'UITN25LMUQC436IM'; $plainText = 'this is a string will be AES_Encrypt'; $aes = new CryptAES(); $aes->set_key($keyStr); $aes->require_pkcs5(); $encText = $aes->encrypt($plainText); $decString = $aes->decrypt($encText); echo $encText,"n",$decString; ?> |
运行结果: fhTD0NNIzv4jUEhJuC1htFFXJ/4S/rL6tDCJPiNvJ8mVLHWOD0HWweuxHynxoZf9 this is a string will be AES_Encrypt java版代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import java.security.Key; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class CryptAES { private static final String AESTYPE ="AES/ECB/PKCS5Padding"; public static String AES_Encrypt(String keyStr, String plainText) { byte[] encrypt = null; try{ Key key = generateKey(keyStr); Cipher cipher = Cipher.getInstance(AESTYPE); cipher.init(Cipher.ENCRYPT_MODE, key); encrypt = cipher.doFinal(plainText.getBytes()); }catch(Exception e){ e.printStackTrace(); } return new String(Base64.encodeBase64(encrypt)); } public static String AES_Decrypt(String keyStr, String encryptData) { byte[] decrypt = null; try{ Key key = generateKey(keyStr); Cipher cipher = Cipher.getInstance(AESTYPE); cipher.init(Cipher.DECRYPT_MODE, key); decrypt = cipher.doFinal(Base64.decodeBase64(encryptData)); }catch(Exception e){ e.printStackTrace(); } return new String(decrypt).trim(); } private static Key generateKey(String key)throws Exception{ try{ SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); return keySpec; }catch(Exception e){ e.printStackTrace(); throw e; } } public static void main(String[] args) { String keyStr = "UITN25LMUQC436IM"; String plainText = "this is a string will be AES_Encrypt"; String encText = AES_Encrypt(keyStr, plainText); String decString = AES_Decrypt(keyStr, encText); System.out.println(encText); System.out.println(decString); } } |
运行结果: fhTD0NNIzv4jUEhJuC1htFFXJ/4S/rL6tDCJPiNvJ8mVLHWOD0HWweuxHynxoZf9 this is a string will be AES_Encrypt 转自: http://alunblog.duapp.com/?p=17
View Details打开 D:\Tomcat8027\conf\tomcat-users.xml 在tomcat-users节点里添加: <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="admin-gui"/> <role rolename="manager-gui"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/> <user username="admin" password="admin" roles="admin-gui,manager-gui"/> 重启tomcat,就可以用admin登录了。PS:其他用户也可以不要。
View Details准备工作 环境说明:win7(64位),已安装iis7.5,已安装JDK。 首先下载Tomcat8:http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.27/bin/apache-tomcat-8.0.27-windows-x64.zip 下载连接器:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/tomcat-connectors-1.2.40-windows-x86_64-iis.zip Tomcat 解压tomcat到D:\Tomcat8027。 以管理员身份运行:D:\Tomcat8027\bin\service.bat,执行成功后启动服务:Apache Tomcat 8.0 Tomcat8。 在浏览器中输入:http://localhost:8080,如果显示tomcat页面,说明安装成功。 连接器 从连接器压缩包解压isapi_redirect.dll到D:\Tomcat8027\conf。 把以下代码保存为tomcat_iis.reg,并双击导入注册表。 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Jakarta Isapi Redirector\1.0] "extension_uri"="/jakarta/isapi_redirect.dll" "log_file"="D://Tomcat8027//logs" "log_level"="debug" "tomcat_start"="D://Tomcat8027//bin//startup.bat" "tomcat_stop"="D://Tomcat8027//bin//shutdown.bat" "worker_file"="D://Tomcat8027//conf//workers.properties" "worker_mount_file"="D://Tomcat8027//conf//uriworkermap.properties" 在D:\Tomcat8027\conf下创建三个文件: workers.properties workers.tomcat_home=D:\Tomcat8027\ workers.java_home=D:\Program Files\Java\jdk1.8.0_51 ps=\ worker.list=worker1 worker.worker1.port=8009 worker.worker1.host=localhost worker.worker1.type=ajp13 worker.worker1.lbfactor=1 uriworkermap.properties /*.jsp=worker1 isapi_redirect.properties extension_uri=/jakarta/isapi_redirect.dll log_file=D:\Tomcat8027\logs\isapi_redirect.log log_level=info worker_file=D:\Tomcat8027\conf\workers.properties worker_mount_file=D:\Tomcat8027\conf\uriworkermap.properties IIS站点的设置 首先点击IIS管理器根节点,双击“ISAPI和CGI限制”,右键“添加”,ISAPI或CGI路径:D:\Tomcat8027\conf\isapi_redirect.dll,描述:jakarta,勾选“允许执行扩展路径”。 然后创建一个站点:TestJsp,并绑定testjsp主机名,并在hosts文件里绑定,我的物理路径是:F:\TEST\JSP。 在站点下新建虚拟目录jakarta,别名要和注册表里的一致,所以要用:jakarta,物理路径:D:\Tomcat8027\conf。 点击站点下的jakarta,双击“处理程序映射”,点击第三栏的菜单“编辑功能权限”,勾选“执行”。 点击TestJsp站点,双击“ISAPI筛选器”,添加一个筛选器,筛选器名称:jakarta,可执行文件:D:\Tomcat8027\conf\isapi_redirect.dll。 打开D:\Tomcat8027\conf\server.xml,在Engine标签里添加一个Host元素: <Host name="testjsp" appBase="." unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="/" reloadable="true" docBase="F:\TEST\JSP" workDir="F:\TEST\JSP"></Context> </Host> ps:name、iis绑定的主机名、hosts的指向名称一定要一致。 在F:\TEST\JSP下添加测试文件test.jsp: <%@ page language="java"%> <%@ page contentType="text/html; charset=utf-8"%> <%@ page import="java.util.*"%> <%@ page import="java.text.*"%><% […]
View Details1、前言 在游戏开发中很多功能按权重随机给东西,比如:掉落、奖励、抽奖等等….. 2、功能 *)支持多个权重进行随机 *)能屏蔽指定权重,防止再次随机到 3、实现 [java] view plaincopy public int weightRandom(BitSet exclude, int… weights) { if (weights == null) { //安全性验证 } int length = weights.length; if (length == 0) { return –1; } if (len == 1) { int w = weights[0]; if (w < 0) { //安全性验证 } else if (w == 0) { return –1; } else { return 0; } } int total = 0; for (int i = 0; i < len; i++) { if (exclude != null && exclude.get(i)) { continue; } int w = weights[i]; total += w; } if (total <= 0) { return –1; } int randomNum = random(1, total), hitIndex = –1, partNum = 0; for (int i = 0; i < len; i++) { if (exclude != null && exclude.get(i)) { continue; } int w = weights[i]; partNum += w; if (partNum >= randomNum) { hitIndex = i; break; } } return hitIndex; } from:http://blog.csdn.net/zeus_9i/article/details/11900015
View Details一、问题定义: 问下有一个数组,这些数组中的值都有自己的权重,怎样设计才能高效的优先取出权重高的数?? 例如: 复制代码代码如下: 权重: 8 2 11 79 权重返回的值: 0 1 2 3 二、分析问题: 思路一:创建一个数组数组大小为权重和的大小,如值0的权重是8,则放入8个0值,值1的权重是2,则放入2个1值,依次类推。 然后用用一个权重和大小的随机数,产生随机数,即可。缺点要占用过多的内存。 思路二: 权重和数组 w[i]存储的是[0,i]元素的所有元素的权重和 时间复杂度O(n) 空间复杂度O(n) 随机[0,W[399]] 看随机数 落在哪个Wi 内就选哪个 时间复杂度 O(longn) 所以总的时间复杂度时间复杂度O(n) 空间复杂度O(n) 伪代码: 轮盘赌 并不是一种特别好的选择算子,但它容易实现。 首先要明白一点,由于交叉、变异等算子,并不能控制进化方向,所以进化的重任落在选择算子上。 如果明白了这一点,就好办了。 轮盘赌,就是积累概率来实现的,通常适应度大的被选择的几率较高。 假如:fit为适应度数组,共m个 复制代码代码如下: for i=1 to m '先求和 sum=sum+fit(i) next i For i = 1 To n ‘n-是要生成多少个个体 temp = temp + fit(i) If rnd <= temp / sum Then 输出 i 就是结果 Exit Function End If Next i 三、解决问题: 复制代码代码如下: package datastruct; import java.util.HashMap; import java.util.Map; /** 权重随机数: 如 权重:8 2 11 […]
View Details如果你是一名Web开发人员,那么用膝盖想也知道你的职业生涯大部分将使用Java而度过。这是一款商业级的编程语言,我们没有办法不接触它。 对于Java,有两种截然不同的观点:一种认为Java是最简单功能最强大的编程语言之一,另一种则表示这种编程语言既难用又复杂。 下面这些工具或许功能和作用不同,但是有着一个共同的主旨,那就是——它们都是为了给Java编码和开发提供卓越的支持。 1. JDK(Java开发工具包) 如果你打算用Java开发一些小程序和应用程序,那么首先得给自己准备一个类似于JDK的工具,其中包括必要的Java Complier、Java Runtime Environment(JRE)和Java API。这是开始Java之旅的第一步。 官方网站:http://java.com/en/download/faq/develop.xml 2. Eclipse IDE 如果咨询一些经验丰富的Java开发人员关于他们最喜欢的Java Integrated Development Environment(IDE)是什么,不少人会告诉你是Eclipse IDE。 Eclipse能提供关于代码完成、重构和语法检查这些急需的帮助。它还能提供JDT的一系列工具,包括各种插件工具来帮助开发各种Java应用。 此IDE的真正优势是它允许开发人员使用不同的语言支持,如它也可以提供C/ C++和PHP 的IDE。这使得它成为了Java开发的一个一站式资源。 官方网站:http://www.eclipse.org/ 3.NetBeans 这又是一个IDE,提供了功能全面的阵列,如转换器,编辑器和代码分析器,这些工具可以帮助你使用最新的Java技术实现应用程序。工具范围相当广泛,而且IDE背后的团队也在不断地改进。此外你还可以得到静态分析工具的帮助——编写出无bug的代码。 官方网站:https://netbeans.org/ 4. IntelliJ IDEA 13.1 据传它有“最智慧的Java IDE”之称。如果你尝试过后,就会发现它所言不虚,因为它能帮助开发人员拿出最具有创造性的解决方案。它的“Smart Code Completion”和“On-the-fly Code Analysis”功能等可以提高开发人员的工作效率,并且还提供了对web和移动开发高级支持。所以,不妨试试这个好助手。 官方网站:http://www.jetbrains.com/idea/ 5.Oracle JDeveloper 如果你正在寻找一个免费的IDE来构建一个面向服务的架构,那没有比JDeveloper更好的了。它支持完整的开发生命周期,这意味着你可以放心自豪名正言顺地使用ava解决方案。 官方网站:http://www.oracle.com/technetwork/developer-tools/jdev/overview/index.html 6. JUnit 这是一个可以帮助开发人员编写和运行测试的单元测试框架。但是JUnit和市场上一些类似的框架还有着本质的区别。你可以一次测试一个代码块,而不需要等待该模块在运行测试前完成。实际上就是你可以“先测试,然后写代码”,这意味着对于应用程序的最终功能如何你可以先放下心中的大石了。 官方网站:http://junit.org/ 7. Apache ANT™ 这是一个开源工具,其最大的优势就是简单。关键是可以实现开发人员处理复杂和重复性任务的目标。ANT™,可以自动执行此类任务。这还只是其众多简化功能之一而已。 官方网站:http://ant.apache.org/ 8. JRAT(Java Runtime Analysis Toolkit) 如果你想要评测应用程序的性能,那么就必须具备JRAT这个分析工具。有了这个工具,你可以找出潜在的可能会影响应用程序性能的问题域。 官方网站:http://jrat.sourceforge.net/ 9.Apache JMeter™ 这是Apache的另一种工具,主要用于测试。它可以评测功能行为以及网站、数据库、Web服务等的性能。它有一个易于理解的GUI,这一事实意味着你可以轻松地构建测试计划并迅速调试应用程序。 官方网站:http://jmeter.apache.org/ 10.Apache Maven 上面曾提到过Apache ANT™,而现在的Maven能帮助你做同样的事情。不过,很多开发人员表示相比ANT™,Maven前进了一大步。在依赖管理、构建行动、调试和协作方面,它都比ANT™略高一筹。简单地说,如果你正在使用ANT™,那么你需要告诉它到底应该怎么做:你需要提供资源的确切位置,分配生成的位元码的存储位置以及用JAR文件打包。 Maven,换句话说,则简化了这些东西。 官方网站:http://maven.apache.org/index.html 11.Gradle 如果你想要有这样一种工具,可以结合ANT™和Maven的优点,那么你一定会喜欢Gradle。有了Gradle,你就可以在Groovy编码——这是一个巨大的优势,因为它允许你编写任何代码。这个工具的第二大优势是,它支持惯例优先配置的模式。 官方网站:http://www.gradle.org/ 12.Clover 该工具提供了Java和Groovy代码覆盖。Clover能让你直接瞄准问题可能性最大的部分,确保测试侧重于特定代码。 官方网站:https://www.atlassian.com/software/clover/overview 13.YourKit 这是一个Java分析工具,允许在开发或生产过程中按需分析:这意味着你可以确保你的产品符合最高的质量标准。按需分析指的是,被分析的应用程序可以在不产生任何费用的情况下运行。 官方网站:http://www.yourkit.com/ 14.Mockito 如果你想用干净和简单的API编写测试,Mockito应该就是你的首选。Mockito本质上是一个模拟库,可以帮助你创建、验证和清除模块——Java开发的几个重要方面。 官方网站:https://code.google.com/p/mockito/ 15. FindBugs的™ Java代码有bug?如何才能找到它们呢?——没错,就是FindBugs的™。它不但免费,还易于操作,真心很不错! 官方网站:http://findbugs.sourceforge.net/ 这15个工具,能让你的Java开发工作更为轻松便捷,但是前提是要因地制宜,根据需求选择适合的工具,然后你才能受益无穷。 from:http://www.php100.com/html/it/biancheng/2015/0121/8428.html
View Details原因1:给定目录下jvm.dll不存在。 对策:(1)重新安装jre或者jdk并配置好环境变量。(2)copy一个jvm.dll放在该目录下。 原因2:eclipse的版本与jre或者jdk版本不一致 对策:要么两者都安装64位的,要么都安装32位的,不能一个是32位一个是64位。 原因2的概率更大一些,原因1不太可能发生。 from:http://blog.csdn.net/zyz511919766/article/details/7442633/
View Details解决方法:
<appSettings>
<add key="disableLuceneLocks" value="true" />
</appSettings>
在配置文件中加入这句就可以解决问题了。
from:http://www.oschina.net/question/1859_23187
有一次更新完代码启动系统,系统报如下异常:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
java.lang.RuntimeException: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@D:\opt\xxxx_index\place\write.lock at com.xxxx.vst.search.lucene.search.Searcher.init(Searcher.java:74) at com.xxxx.vst.search.lucene.search.Searcher.<init>(Searcher.java:53) at com.xxxx.vst.search.lucene.LuceneContext.init(LuceneContext.java:51) at com.xxxx.vst.search.listener.LuceneContextIniter.contextInitialized(LuceneContextIniter.java:21) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) at org.apache.catalina.core.StandardService.start(StandardService.java:525) at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) at org.apache.catalina.startup.Catalina.start(Catalina.java:595) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@D:\opt\xxxx_index\place\write.lock at org.apache.lucene.store.Lock.obtain(Lock.java:84) at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:644) at com.xxxx.vst.search.lucene.search.Searcher.init(Searcher.java:65) ... 18 more |
经查,IndexWriter的构造函数在试图获取另外一个IndexWriter已经加锁的索引目录时就会抛出一个LockObtainFailedException。但是我们系统中并没有多个IndexWriter去指定同一个目录,走查代码才发现,原来是同一个初始化方法调用了两次,一次是spring监听器里调用的,另一个是另一同事测试方便,在static模块里调用的,导致同一个lucene上下文初始化方法被调用两次,建议static模块要慎用,因为它会悄悄神不知鬼不知自己悄悄被调用。
from:http://www.tuicool.com/articles/2UBVnq7