java的new date()于linux时间不一致

我的程序中时间使用的new Date();在windows下时间都没有问题,现在部署到linux下;
new Date()是一个时间,使用date命令是一个时间,使用hwclock命令又是另一个时间,
请问应该如何调整到时间一致?

5个回答

同步到一致啊。。。。。。。

谢谢大家,解决了.是jdk的问题.要重装jdk然后jdk的时间就同步到系统时间了

Date 里面 那么多时间格式,你可以自己设定的。

手动先设置服务器时间一致

有时间先后执行顺序的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java.util.Date的问题
windows下:System.out.println(new Date(1484200800000l));,结果为Thu Jan 12 14:00:00 CST 2017,没问题 linux下:输出Thu Jan 12 01:00:00 EST 2017,不是简单的相差8小时 关键是在linux上new Date输出和linux命令date,输出是一样的结果,都是当前时间, 会是什么问题?
关于java程序在linux服务器和windows机器运行效率问题
同样的java程序在linux服务器上要比在windows服务器上慢很多,jdk都是1.7版本。 linux服务器是4U,64核,128G,windows服务器是i7,16G。 写了一个小的demo测试了一下: ``` public static void main(String[] args) { Date date=new Date(); DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time1=format.format(date); System.out.println("开始时间:"+time1); long begin = System.currentTimeMillis(); for(int i=0;i<100000;i++){ for(int j=0;j<100000;j++){ for(int k=0;k<100000;k++){ int a = i+j+k; } } } long end = System.currentTimeMillis(); Date date1=new Date(); String time2=format.format(date1); System.out.println("结束时间:"+time2); System.out.println("运行时间:"+(end-begin)+"ms"); } ``` 在windows机器上运行时间是25s,打成jar包在linux服务器上运行的时间是50s。
求助:java读取linux文件问题
private final String PATH = "/mbp/file/cmbc/rechg/"+new SimpleDateFormat("yyyyMMdd").format(new Date())+"/单笔联机代付THWJ_XXX_"+new SimpleDateFormat("yyyyMMdd").format(new Date())+".txt"; private static final Logger log = Logger.getLogger(ReExchangeUpload.class); @Override public void execute(JobExecutionContext arg0) throws JobExecutionException { List<String> list = new ArrayList<String>(); try { File file = new File(PATH); log.info("文件目录"+PATH); if (file.isFile() && file.exists()) { InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK"); BufferedReader br = new BufferedReader(isr); String lineTxt = null; while ((lineTxt = br.readLine()) != null) { if ("########".equals(lineTxt)) { break; } list.add(lineTxt); } br.close(); } else { log.info("文件不存在"); return; } } catch (Exception e) { log.info("文件读取失败"); } ![图片说明](https://img-ask.csdn.net/upload/201710/14/1507992995_395452.jpg) ![图片说明](https://img-ask.csdn.net/upload/201710/14/1507992962_571994.jpg) 文件地址没错,为什么读取失败了,求大神
Shell脚本中执行kill之后就结束,不在往下执行nohup命令
编写这个脚本是用来检测开发是否使用FTP上传了新的文件 在定时任务里每分钟执行一次,对比大小来重启Java ```shell #!/bin/bash #判断文件大小-更新文件 触发Java重启 #查看当前文件大小 new_size=$(ls -l /www/test.jar | awk '{print $5}') #查看历史文件大小 look_size=$(cat /www/size) #查看Java进程 java_ps=$(ps -ef|grep java | grep -v 'grep'|awk '{print $2}') #重启Java ReJava(){ echo "[信息]$(date +"%Y年%m月%d日 %T") 文件不相同,正在重启!" >> /data/logs/rejava.log kill $java_ps nohup java -jar /www/test.jar >/www/log.log 2>&1 & ls -l /www/test.jar | awk '{print $5}' > /www/size } #不重启Java NoReJava(){ echo "[信息]$(date +"%Y年%m月%d日 %T") 文件相同,无需重启!" >> /data/logs/rejava.log } #判断文件大小是否发生变化 if [ $look_size != $new_size ] then ReJava else NoReJava fi ``` 已经使用bash -x查看过程,看不出什么问题就莫名其妙结束了 显示Terminated后结束脚本,ReJava函数里的nohup命令不在往下执行
现在是一些关键操作要记录操作日志,但是在insert的时候,偶然会出现插入失败的问题.现在找不到问题所在?
执行代码 ``` HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); SsOperLog ssOperLogEntity = new SsOperLog(); ssOperLogEntity.setOperNo(Long.valueOf(IdGenarater.nextStringValue()));//操作流水号 UserInfo users = Util.getSessionUserInfo(request);//登录用户 if (users == null) {//用户还未登录 String workCode = request.getParameter("workCode"); String urlString = request.getHeader("host"); //根据域名获取部门编号 String deptCode = loginService.getDeptCodeByDomainName(urlString); users = loginService.selectByUserIdAndPassword(workCode, null, deptCode); if (users == null) { return point.proceed(); } } ssOperLogEntity.setDeptCode(users.getDeptCode());//用户机构 ssOperLogEntity.setOperId(Long.valueOf(users.getOperId()));//用户id ssOperLogEntity.setOperName(users.getOperName());//操作员 ssOperLogEntity.setDeptName(users.getDeptName()); ssOperLogEntity.setOperDate(new Date(System.currentTimeMillis()));//操作日期 ssOperLogEntity.setOperTime(new Date(System.currentTimeMillis()));//操作时间 String rquestName = getMthodRemark(point);//操作名称(对应注解里面的remark信息) String operType = getMthodOperType(point);//操作类型(对应注解里面的opertype信息) String processMethod = point.getSignature().getName();//请求处理方法名 ssOperLogEntity.setReruestId(request.getRequestURI());//请求url ssOperLogEntity.setRquestName(rquestName); if(operType.length()>1){ //获取大类类型 ssOperLogEntity.setCategories(operType.substring(0,1)); } ssOperLogEntity.setProcessMethod(processMethod); ssOperLogEntity.setOperType(operType); ssOperLogEntity.setLocalAddress(request.getRemoteAddr()); if (!"/aa/login/checkLogin.do".equals(request.getRequestURI())) { String requestParams = JSONObject.toJSONString(request.getParameterMap()); ssOperLogEntity.setRequestParams(requestParams); }//请求参数 Object[] method_param = null; Object object; try { method_param = point.getArgs(); //获取方法参数 object = point.proceed(); } catch (Exception e) { ssOperLogEntity.setOperState(OperateStatusEnum.FAIL.getCode());//操作失败 ssOperLogEntity.setExceptionMesg(e.getMessage()); if (e.getMessage() == null) { ssOperLogEntity.setExceptionMesg(e.toString()); } mongoTemplate.insert(ssOperLogEntity); // ssOperLogMapper.insert(ssOperLogEntity); throw e; } ssOperLogEntity.setOperState(OperateStatusEnum.SUCC.getCode());//操作成功 mongoTemplate.insert(ssOperLogEntity); // 这里报错 // ssOperLogMapper.insert(ssOperLogEntity); return object; } ``` 异常信息:appserver-b4 等同于ip地址 ``` org.springframework.dao.DataAccessResourceFailureException: Operation on server appserver-b4:27017 failed; nested exception is com.mongodb.MongoException$Network: Operation on server appserver-b4:27017 failed at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:77) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2128) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:461) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.insertDBObject(MongoTemplate.java:1026) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:835) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:776) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:767) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at com.wx.app.ygp.service.log.LogService.doBefore(LogService.java:115) ~[classes/:na] at sun.reflect.GeneratedMethodAccessor867.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:654) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at com.wx.app.ygp.action.system.LoginController$$EnhancerBySpringCGLIB$$3d4c3a49.checkLogin(<generated>) ~[classes/:na] at sun.reflect.GeneratedMethodAccessor1317.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) [servlet-api.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:167) [spring-session-1.3.1.RELEASE.jar:na] at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80) [spring-session-1.3.1.RELEASE.jar:na] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94) [catalina.jar:8.0.44] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [catalina.jar:8.0.44] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.44] at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.44] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502) [catalina.jar:8.0.44] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132) [tomcat-coyote.jar:8.0.44] at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684) [tomcat-coyote.jar:8.0.44] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533) [tomcat-coyote.jar:8.0.44] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489) [tomcat-coyote.jar:8.0.44] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.44] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162] Caused by: com.mongodb.MongoException$Network: Operation on server appserver-b4:27017 failed at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:215) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.writeWithCommandProtocol(DBCollectionImpl.java:567) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.insertWithCommandProtocol(DBCollectionImpl.java:528) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.insertImpl(DBCollectionImpl.java:206) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:176) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:93) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:78) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:120) ~[mongo-java-driver-2.14.3.jar:na] at org.springframework.data.mongodb.core.MongoTemplate$9.doInCollection(MongoTemplate.java:1031) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:459) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] ... 63 common frames omitted Caused by: java.net.SocketException: Broken pipe (Write failed) at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_162] at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) ~[na:1.8.0_162] at java.net.SocketOutputStream.write(SocketOutputStream.java:155) ~[na:1.8.0_162] at org.bson.io.PoolOutputBuffer.pipe(PoolOutputBuffer.java:153) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.sendWriteCommandMessage(DBCollectionImpl.java:639) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.access$300(DBCollectionImpl.java:50) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl$4.execute(DBCollectionImpl.java:576) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl$4.execute(DBCollectionImpl.java:567) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBPort.doOperation(DBPort.java:187) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:208) ~[mongo-java-driver-2.14.3.jar:na] ... 72 common frames omitted ``` 配置MongoDB文件: ``` mongo.hostport=127.0.0.1:27017 mongo.connectionsPerHost=100 mongo.threadsAllowedToBlockForConnectionMultiplier=6 mongo.dataName=ygp mongo.username=ygp mongo.password=ygp_admin mongo.connectTimeout=60000 mongo.maxWaitTime=120000 mongo.autoConnectRetry=true mongo.socketKeepAlive=true mongo.socketTimeout=1500 mongo.slaveOk=true <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!--设置用户验证--> <bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials"> <constructor-arg name="username" value="${mongo.username}" /> <constructor-arg name="password" value="${mongo.password}" /> </bean> <!-- 定义mongo对象,对应的是mongodb官方jar包中的Mongo,replica-set设置集群副本的ip地址和端口 --> <mongo:mongo id="mongo" replica-set="${mongo.hostport}"> <!-- 一些连接属性的设置 --> <mongo:options connections-per-host="${mongo.connectionsPerHost}" threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}" connect-timeout="${mongo.connectTimeout}" max-wait-time="${mongo.maxWaitTime}" auto-connect-retry="${mongo.autoConnectRetry}" socket-keep-alive="${mongo.socketKeepAlive}" socket-timeout="${mongo.socketTimeout}" slave-ok="${mongo.slaveOk}" write-number="1" write-timeout="0" write-fsync="true" /> </mongo:mongo> <!-- mongo的工厂,通过它来取得mongo实例,dbname为mongodb的数据库名,没有的话会自动创建 --> <bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory"> <constructor-arg ref="mongo" /> <constructor-arg value="${mongo.dataName}" /> <constructor-arg ref="userCredentials" /> </bean> <bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" /> <!--排除 _class --> <bean id="defaultMongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper"> <constructor-arg name="typeKey"> <null /> </constructor-arg> </bean> <!-- collection的映射 --> <bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mappingContext" ref="mappingContext" /> <property name="typeMapper" ref="defaultMongoTypeMapper" /> </bean> <!-- mongodb的主要操作对象,所有对mongodb的增删改查的操作都是通过它完成 --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mongoConverter" ref="mappingMongoConverter" /> </bean> </beans> ```
jquery 对 java后台换回的 json解析失败
ff上报错是:SyntaxError: JSON.parse: unexpected keyword at line 1 column 1 of the JSON data 前端代码 ``` ChatMassage cm = ChatMassage.instance(); String mas = cm.getMassage(num); int massageNumber = ChatMassage.mass_num; System.out.println("mnumber:"+massageNumber); session.setAttribute("massageNumber", massageNumber); JSONObject json = new JSONObject(); json.put("massage", mas); json.put("massageNumber", massageNumber); System.out.println(json); return json; ``` 前端问题 ``` function loadMassage(){ $.ajax({ data: "num=" + massageNumber, url: "loadData.do", Success: $(function(msg){ var res =$.parseJSON(msg); alert(parseInt(res.massageNumber)); massageNumber=parseInt(res.massageNumber); massages+=res.massgae; document.body.innerHTML=massages; }) }); ``` json生成部分 ``` } else { cm.addUser(name); HttpSession session = request.getSession(); session.setAttribute("username", name); SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); String data = dateFormat.format(new Date()); cm.setMassage("<br><font color=\'red\'> welcom "+name+" join in chatting" + " at "+data+"</font><br>"); } ``` ``` request header: Host: localhost:8080 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0 Accept: */* Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://localhost:8080/spring/chat X-Requested-With: XMLHttpRequest Cookie: JSESSIONID=26FBFB1DFC7729A3E1A423AECA8B2995 DNT: 1 Connection: keep-alive Response Header: Server: Apache-Coyote/1.1 Content-Type: : application/json Content-Length: 108 Date: Mon, 25 Dec 2017 16:33:01 GMT ``` 在返回时已设置编码 ``` Object result = action.execute(request, response); if(result instanceof String) { request.getRequestDispatcher(result.toString()).forward(request, response); } else if (result instanceof JSONObject) { response.setHeader("Content-Type:", "application/json"); response.setCharacterEncoding("utf-8"); response.getWriter().print((JSONObject)result); } ``` 因为是 Linux 系统,所以一般情况下不会出现编码问题。并且我也将中文全部替换为英文。 之前在没开 debug 时,解析全部为 undefinded
嵌入式安卓附件下载始终为0kb
附件在安卓机上无法下载,在ios上可以下载,直接用浏览器也可以下载。 前端代码: ``` window.location.href = G_CTX_PATH + "/mobile/xxxx/downloadFile?attachmentId="+attachmentId+"&userToken="+encodeURIComponent(encodeURIComponent(userToken)); ``` 后端是通过java io 去读取响应的。 抓包看的,数据正常响应回来,但是安卓机保存后就0kb。 我们前端代码是 html5嵌入在别人的app里面的,点击附件下载时。app就代码本机浏览器去访问链接。 感觉应该是前端处理问题,求大佬告知。 前段换成这种方式了 function downloadFiles(attachmentId,name){ //var TK = $("#TK").val(); //"&TK="+TK+ var userToken =$("#userToken").val(); //window.location.href =G_CTX_PATH + "/mobile/common/downloadFile?attachmentId="+attachmentId+"&userToken="+encodeURIComponent(encodeURIComponent(userToken)); openDownloadDialog(G_CTX_PATH + "/xxxx/common/downloadFile?attachmentId="+attachmentId+"&userToken="+encodeURIComponent(encodeURIComponent(userToken)),name); }; function openDownloadDialog(url, saveName) { if(typeof url == 'object' && url instanceof Blob) { url = URL.createObjectURL(url); // 创建blob地址 } var aLink = document.createElement('a'); aLink.href = url; aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效 var event; if(window.MouseEvent) event = new MouseEvent('click'); else { event = document.createEvent('MouseEvents'); event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); } aLink.dispatchEvent(event); }; 补充:报文信息 第一次请求 GET http://xxx.xxx.xxx.xxx:9088/xxxxx/xxxx/common/downloadFile?attachmentId=xxxx&userToken=xxxxx HTTP/1.1 Host: xxx.xxx.xxxx.xxx:9088 Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Linux; Android 9; HWI-AL00 Build/HUAWEIHWI-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: zh-Hans-CN,zh-Hant-HK;q=0.8,en-US;q=0.6 Cookie: JSESSIONID=xxxxxxx HTTP/1.1 200 OK Content-Disposition: attachment; filename="xxxx.jpg" Content-Type: application/octet-stream;charset=UTF-8 Content-Length: 1066724 Date: Wed, 30 Oct 2019 02:20:51 GMT Server: OWN/8.5 第二次 GET http://xxx.xxx.xxx.xxx:9088/xxxx/mobile/xxxx/downloadFile?attachmentId=xxx&userToken=xxxx HTTP/1.1 Host: xxx.xxx.xxx.xxx:9088 Connection: Keep-Alive Accept-Charset: utf-8 Accept-Encoding: utf-8 Accept-Language: zh-CN User-Agent: Mozilla/5.0 (Linux; Android 9; HWI-AL00 Build/HUAWEIHWI-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 Range: bytes=0- Referer: ext:/lp:home Accept: multipart/mixed,text/html,image/png,image/jpeg,image/gif,image/x-xbitmap,application/vnd.oma.dd+xml,*/* Cookie: JSESSIONID=xxxx HTTP/1.1 200 OK Date: Wed, 30 Oct 2019 02:21:03 GMT Server: OWN/8.5 Content-Length: 48 Terminate because of csrf!http://xxx.xxxx.xxx.xxx ===========================================分割线 问题已经解决了,前段换了上面的第二种js 后台的话被拦截器拦截了,有csrf防攻击拦截器, 本来打算优雅点解决,通过js置空referer但是前端功底太弱,没办反只能后台改了拦截器降低拦截力度,只拦截post请求。帖子结了,分给一楼捧场的小伙伴了。
请问大神如何将下面的Perl转换成java版本
最好能写出详细的方法,我现在能够实现的是用.properties连接数据库 想转换成java版本,打成jar包放到linux环境的定时任务执行 my ($sum_level,$sql,$dbhome,$gsm_type,$lte_type,$start_time,$end_time,$db_type,$scm,$programe,$start_date,$end_date,$db_ini,$detials_time,$detiale_time,$ustime); my ($cmd_line,$app_name,$province_id,$Convert_type,$debug,$detail_log_name,$flag,$range_second,$todaysum); my $dbhome = $ENV{"DB_PATH"}; if((!defined($dbhome) || ! -d $dbhome)) { die("Do not define the env 'DB_PATH' or it does not exist\n"); } my $cmd_line = $0." ".join(" ",@ARGV); my $programe = $0; $programe =~ /\b(\w+)\.pl/i; my $app_name = $1; my $db_ini = "$dbhome/db.ini"; my $gsm_type = "GSM"; my $lte_type = "LTE"; GetOptions( "u=i" =>\$sum_level, "s:s" =>\$start_time, "e:s" =>\$end_time ); my $scm = new SumCommonModule("$app_name",$debug,$detail_log_name,$$); $scm->connect_db($db_ini); my $db_type = $scm->get_db_type(); if($sum_level ==1 ) { $start_time = int2date(date2int(current()) - 24*3600) if($start_time eq ""); $end_time = $start_time if($end_time eq ""); } elsif($sum_level ==3 ) { $start_time = int2date(date2int(current()) - 24*28*3600) if($start_time eq ""); #��Ҫ�Զ����㴦 $end_time = $start_time if($end_time eq ""); } else { die("Please input sum_level Parameter ,The sum_level must be in(1,3) \n"); } ($start_time,$end_time) = time_range($start_time,$end_time,$sum_level,"T"); ($detials_time,$detiale_time) = time_range($start_time,$end_time,3,"D"); my ($start_date,$end_date) = time_range($start_time,$end_time,$sum_level,"D"); $ustime = TimeOpt::GMtime($start_time,"-1D"); $ustime = TimeOpt::CFtime("MM/DD/YYYY",$ustime); print "xxxxxxxxx $sum_level \n"; print "$start_time,$end_time,$detials_time,$detiale_time,$ustime\n"; #<============================================================================= my ($tmp_irms_radio2g_day,$tmp_irms_radio4g_day,$tmp_sitecode_num,$tmp_irms2npm_stcode_traffic,$tmp_last_num); #������ʱ�� create_temp_name("tmp",\$tmp_irms_radio2g_day,\$tmp_irms_radio4g_day,\$tmp_sitecode_num,\$tmp_irms2npm_stcode_traffic,\$tmp_last_num); #<============================================================================= print "xxxxxxxxxxxxxxxb $db_type \n"; $scm->set_sql_note(" Delete irms_radio_cell double cell_name"); $sql = qq { DELETE nrmdb:irms_radio_cell WHERE label_cn in( SELECT a.label_cn FROM nrmdb:irms_radio_cell a,nrmdb:irms_radio_cell b WHERE a.label_cn = b.label_cn AND a.cuid != b.cuid); DELETE irms2npm_stcode_traffic WHERE first_result = '$start_date'; insert into irms2npm_stcode_traffic (first_result, sitecode, codename) select '$start_date' , mobile_sitecode, report_site_code_name from nrmdb:irms_sitecode_cell where 1=1; }; $scm->execute_batch($sql); GSM_cell_sum(); LTE_cell_sum(); my $pattern = "[-\/ :]+"; my $test_date = TimeOpt::CFtime("YYYY-MM-DD "."00:00:00",$start_time); my @splite_list= split(/$pattern/, $test_date); my ($syear,$smon,$sday,$shour,$smin,$ssec) = @splite_list; # MM/DD/YYYY �ж��Ƿ���1�ţ�ִ���»��� if ($sday == 1) { Month_sum( TimeOpt::GMtime($test_date,"-1M") , TimeOpt::GMtime($test_date,"-1D")); } sub GSM_cell_sum() { $scm->set_sql_note("Start $gsm_type cell_sum"); my $sql = qq { CREATE TABLE $tmp_irms_radio2g_day ( int_id integer, first_result datetime year to second, label_cn varchar(255), tch_traffic float ); CREATE INDEX ix0_irms_radio2g_day on $tmp_irms_radio2g_day (int_id,label_cn) ; INSERT INTO $tmp_irms_radio2g_day (int_id ,first_result,tch_traffic) SELECT ne_id,first_result,tch_traffic FROM tpa_radio_sum WHERE first_result='$start_time' AND sum_level=1 AND ne_type=300 AND busy_type=0; UPDATE $tmp_irms_radio2g_day a SET label_cn= ( SELECT userlabel FROM tcc_ne_frame b WHERE a.int_id = b.ne_id AND b.ne_type=300 AND b.confirmed not in(2,5) ) WHERE EXISTS( SELECT 1 FROM tcc_ne_frame b WHERE a.int_id = b.ne_id AND b.ne_type=300 AND b.confirmed not in(2,5) ); SELECT sitecode.sitecode, cell.first_result, sitecode.network_type, sum( cell.tch_traffic) traffic FROM nrmdb:irms_radio_cell sitecode , $tmp_irms_radio2g_day cell WHERE sitecode.label_cn = cell.label_cn AND sitecode.network_type = '$gsm_type' GROUP BY 1,2,3 INTO TEMP $tmp_irms2npm_stcode_traffic with no log; create index ix2_tmp_irms2npm_stcode_traffic on $tmp_irms2npm_stcode_traffic (sitecode); UPDATE irms2npm_stcode_traffic a set tch_traffic= ( SELECT traffic FROM $tmp_irms2npm_stcode_traffic b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' AND b.network_type = '$gsm_type' ) WHERE EXISTS ( SELECT 1 FROM $tmp_irms2npm_stcode_traffic b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' AND b.network_type = '$gsm_type' ); SELECT sitecode,sum(tch_traffic) num FROM irms2npm_stcode_traffic WHERE first_result between '$detials_time' and '$start_date' GROUP BY 1 INTO temp $tmp_sitecode_num with no log ; CREATE INDEX ix0_$tmp_sitecode_num on $tmp_sitecode_num( sitecode); UPDATE irms2npm_stcode_traffic a SET last_traffic = ( SELECT num FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ) WHERE EXISTS ( SELECT 1 FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ); SELECT sitecode,traffic FROM irms2npm_stcode_traffic WHERE first_result = '$detials_time' INTO temp $tmp_last_num with no log ; CREATE INDEX ix0_$tmp_last_num on $tmp_last_num( sitecode); UPDATE irms2npm_stcode_traffic a SET traffic = ( SELECT traffic FROM $tmp_last_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ) WHERE EXISTS ( SELECT 1 FROM $tmp_last_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ); }; $scm->set_sql_note(" Summary $gsm_type sitecode!"); $scm->execute_batch($sql); $scm->drop_temp_table($tmp_irms_radio2g_day,$tmp_sitecode_num,$tmp_irms2npm_stcode_traffic,$tmp_last_num); } sub LTE_cell_sum() { $scm->set_sql_note("Start $lte_type cell_sum"); my $sql = qq { CREATE TABLE $tmp_irms_radio4g_day ( int_id integer, first_result datetime year to second, label_cn varchar(255), upoct float ); CREATE INDEX ix0_irms_radio2g_day on $tmp_irms_radio4g_day (int_id,label_cn) ; INSERT INTO $tmp_irms_radio4g_day (int_id ,first_result,upoct) SELECT ne_id,first_result,up_oct_ul+up_oct_dl FROM tpa_eutrancell_q_sum WHERE first_result='$start_time' AND sum_level=1 AND ne_type=8105 AND busy_type=0; UPDATE $tmp_irms_radio4g_day a SET label_cn= ( SELECT userlabel FROM tcc_ne_frame b WHERE a.int_id = b.ne_id AND b.ne_type=8105 AND b.confirmed not in(2,5) ) WHERE EXISTS( SELECT 1 FROM tcc_ne_frame b WHERE a.int_id = b.ne_id AND b.ne_type=8105 AND b.confirmed not in(2,5) ); SELECT sitecode.sitecode, cell.first_result, sitecode.network_type, sum( cell.upoct) traffic FROM nrmdb:irms_radio_cell sitecode , $tmp_irms_radio4g_day cell WHERE sitecode.label_cn = cell.label_cn AND sitecode.network_type = '$lte_type' GROUP BY 1,2,3 INTO TEMP $tmp_irms2npm_stcode_traffic with no log; CREATE INDEX ix2_tmp_irms2npm_stcode_traffic on $tmp_irms2npm_stcode_traffic (sitecode); UPDATE irms2npm_stcode_traffic a set upoct= ( SELECT traffic FROM $tmp_irms2npm_stcode_traffic b WHERE a.sitecode = b.sitecode and a.first_result = '$start_date' and b.network_type = '$lte_type' ) WHERE EXISTS ( SELECT 1 FROM $tmp_irms2npm_stcode_traffic b WHERE a.sitecode = b.sitecode and a.first_result = '$start_date' and b.network_type = '$lte_type' ); SELECT sitecode,sum(upoct) num FROM irms2npm_stcode_traffic WHERE first_result between '$detials_time' and '$start_date' GROUP BY 1 INTO temp $tmp_sitecode_num with no log ; CREATE INDEX ix0_$tmp_sitecode_num on $tmp_sitecode_num( sitecode); UPDATE irms2npm_stcode_traffic a SET last_oct = ( SELECT num FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ) WHERE EXISTS ( SELECT 1 FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ); SELECT sitecode,oct FROM irms2npm_stcode_traffic WHERE first_result = '$detials_time' INTO temp $tmp_last_num with no log ; CREATE INDEX ix0_$tmp_last_num on $tmp_last_num( sitecode); UPDATE irms2npm_stcode_traffic a SET oct = ( SELECT oct FROM $tmp_last_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ) WHERE EXISTS ( SELECT 1 FROM $tmp_last_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ); }; $scm->set_sql_note(" Summary $lte_type sitecode!"); $scm->execute_batch($sql); $scm->drop_temp_table($tmp_irms_radio4g_day,$tmp_sitecode_num,$tmp_irms2npm_stcode_traffic,$tmp_last_num); } sub Month_sum { my $st = shift; my $et = shift; $st = TimeOpt::CFtime("MM/DD/YYYY",$st); $et = TimeOpt::CFtime("MM/DD/YYYY",$et); $scm->set_sql_note("Start Month_sum cell_sum"); my $sql = qq { SELECT sitecode,sum(upoct) lte_num,sum(tch_traffic) gsm_num FROM irms2npm_stcode_traffic WHERE first_result between '$st' and '$et' GROUP BY 1 INTO temp $tmp_sitecode_num with no log ; CREATE INDEX ix0_$tmp_sitecode_num on $tmp_sitecode_num( sitecode); UPDATE irms2npm_stcode_traffic a SET oct = ( SELECT lte_num FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ) WHERE EXISTS ( SELECT 1 FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ); UPDATE irms2npm_stcode_traffic a SET traffic = ( SELECT gsm_num FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ) WHERE EXISTS ( SELECT 1 FROM $tmp_sitecode_num b WHERE a.sitecode = b.sitecode AND a.first_result = '$start_date' ); }; $scm->execute_batch($sql); $scm->drop_temp_table($tmp_sitecode_num); } $scm->end();
AES解密失败原因找到后,历史数据还有什么办法解出来吗
用AES加密算法加密,windows系统加解密正常,可在linux系统中加密正常,但linux上加密的数据在linux上解不出来,在window上也解不出来,问题原因已找到,并已修改,可原先在linux上产生的加密数据怎样才能解密?原始加密方法: ``` public static String encrypt(String content, String key) { if (isEmpty(key)) { return encrypt(content); } try { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128, new SecureRandom(key.getBytes(encodFormat))); byte[] bytes = kgen.generateKey().getEncoded(); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(bytes, "AES")); byte[] result = cipher.doFinal(content.getBytes(encodFormat)); StringBuffer sb = new StringBuffer(); for (int i = 0; i < result.length; i++) { String hex = Integer.toHexString(result[i] & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } sb.append(hex.toUpperCase()); } return sb.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } ``` 原始解密方法: ``` /** * 解密 * * @param content * @param securityKey * @return */ public static String decrypt(String content, String securityKey) { if (isEmpty(securityKey)) { return decrypt(content); } byte[] bytes = new byte[content.length() / 2]; for (int i = 0; i < content.length() / 2; i++) { int high = Integer.parseInt(content.substring(i * 2, i * 2 + 1), 16); int low = Integer.parseInt(content.substring(i * 2 + 1, i * 2 + 2), 16); bytes[i] = (byte) (high * 16 + low); } try { KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128, new SecureRandom(securityKey.getBytes())); SecretKey secretKey = kgen.generateKey(); SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getEncoded(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] result = cipher.doFinal(bytes); return new String(result); } catch (Exception e) { e.printStackTrace(); } return null; } ``` 现在已经找到原因了,修改后的代码已经能满足所有系统加解密,可是历史数据怎么破解?下边是修改后的代码: ``` package com.ecotech.loginservice.util; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import java.security.SecureRandom; /** * Created by kajya * Date: 2019/06/04 */ public class AESUtil { /** * 编码格式 */ private static final String ENCODING = "UTF-8"; /** * 加密算法 */ public static final String KEY_ALGORITHM = "AES"; /** * 签名算法 */ public static final String SIGN_ALGORITHMS = "SHA1PRNG"; /** * 加密 * * @param content 待加密内容 * @param key 加密的密钥 * @return */ public static String encrypt(String content, String key) { try { KeyGenerator kgen = KeyGenerator.getInstance(KEY_ALGORITHM); SecureRandom random = SecureRandom.getInstance(SIGN_ALGORITHMS); random.setSeed(key.getBytes(ENCODING)); kgen.init(128, random); SecretKey secretKey = kgen.generateKey(); byte[] enCodeFormat = secretKey.getEncoded(); SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, KEY_ALGORITHM); Cipher cipher = Cipher.getInstance(KEY_ALGORITHM); byte[] byteContent = content.getBytes(ENCODING); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); byte[] byteRresult = cipher.doFinal(byteContent); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteRresult.length; i++) { String hex = Integer.toHexString(byteRresult[i] & 0xFF); if (hex.length() == 1) hex = '0' + hex; sb.append(hex.toUpperCase()); } return sb.toString(); } catch (Exception e) { e.toString(); } return null; } /** * 解密 * * @param content 待解密内容 * @param key 解密的密钥 * @return */ public static String decrypt(String content, String key) { if (content.length() < 1) return null; byte[] byteRresult = new byte[content.length() / 2]; for (int i = 0; i < content.length() / 2; i++) { int high = Integer.parseInt(content.substring(i * 2, i * 2 + 1), 16); int low = Integer.parseInt(content.substring(i * 2 + 1, i * 2 + 2), 16); byteRresult[i] = (byte) (high * 16 + low); } try { KeyGenerator kgen = KeyGenerator.getInstance(KEY_ALGORITHM); SecureRandom random = SecureRandom.getInstance(SIGN_ALGORITHMS); random.setSeed(key.getBytes(ENCODING)); kgen.init(128, random); SecretKey secretKey = kgen.generateKey(); byte[] enCodeFormat = secretKey.getEncoded(); SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, KEY_ALGORITHM); Cipher cipher = Cipher.getInstance(KEY_ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] result = cipher.doFinal(byteRresult); return new String(result, ENCODING); } catch (Exception e) { e.toString(); } return null; } } ``` 现在需要把原始加密方法加密的数据都解密出来,解密失败,linux系统加密产生的历史数据,还有办法解出来吗? 附一条测试数据: key:E10ADC3949BA59ABBE56E057F20F883E 密文内容:3BC14F72DADE3A0107373BA8E9ECC377FDCF7F4ECE85698169E6E799FD54F3453E03D1AFA84AD963AD8A7D5E88C977FFC3E43902564EEFA29995640B2548E814F3B772C91D5EE710F9F84479C86F2EEB
SocketException, Broken pipe , 为什么 1000 ?
## linux 上,使用HTTPClient 发送请求到 远程服务器,在1000个并发以内(包括1000) 的时候无任何异常, 但是只要超过1000, 即使是1001, 则出现问题: INFO [08-17 15:52:12] [Thread-2024] org.apache.http.impl.client.DefaultRequestDirector.tryExecute(696) | I/O exception (java.net.SocketException) caught when processing request to {}->http://192.168.4.190:80: Broken pipe INFO [08-17 15:52:12] [Thread-2024] org.apache.http.impl.client.DefaultRequestDirector.tryExecute(706) | Retrying request to {}->http://192.168.4.190:80 ## 不知道为什么是 1000 , 不知道哪里有限制 刚好是1000 。 ## windows上执行同样的代码就没有这样的问题现象。这太奇怪了, 我百思不得其解。 请求各位大神看看。 java代码: import java.io.File; import java.util.Date; import java.util.concurrent.ExecutionException; public class TestHTTP { // 线程池的容量 /** * @param args * @throws ExecutionException * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException, ExecutionException { int cnt = 2001; if (args.length > 0 ) { cnt = StringUtil.str2Int(args[0]); } System.out.println(111 + new Date().toString()); for (int i = 0; i < cnt; i++) { TTT ttt = new TTT();// f, "test" Thread t = new Thread(ttt); t.start(); } } } class TTT extends Thread { @Override public void run() { String pathname = "E:\\test\\cca.txt"; pathname = "C:\\Users\\Public\\Documents\\data.txt"; pathname = "/usr/linkapp/bin/tomcat-master/lktest/data.txt"; File f = new File(pathname); String key = LKRestUtil.put(f); System.out.println(" key : " + key + new Date().toString()); } } LKRestUtil.put 方法 : HttpClient httpClient = getHttpClient(); // 从连接池中获取 String url = "http://"+MyNodeStatusChecker.mainHost +"/cmd/put"; HttpPost httppost = new HttpPost(url); httppost.setHeader("content-type", "application/octet-stream"); httppost.setHeader("x-my-policy", policy ); httppost.setHeader("Connection", "keep-alive"); ByteArrayEntity entity = new ByteArrayEntity(data); httppost.setEntity(entity); String key = ""; try { HttpResponse response = httpClient.execute(httppost, context); HttpEntity entity2 = response.getEntity(); if (entity2 != null) { StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { Header[] allHeaders = response.getAllHeaders(); for (int i = 0; i < allHeaders.length; i++) { Header header = allHeaders[i]; if ("x-my-key".equals(header.getName())) { key = header.getValue(); //System.out.println(header.getName() +" : "+ header.getValue()); } } } else { return "MyError:"+statusCode; } } else { return "MyError: entity2 is null "+ entity2; } EntityUtils.consume(entity); } catch (Exception e) { httppost.abort(); logger.error("My出现异常: " + e.toString()); return "MyError:" + e.getMessage(); }finally{ httppost.releaseConnection(); }
JDK8构建报错了,哪位大神帮忙看下原因?
我的代码是从java.net网站下载的,名称为openjdk-8-src-b132-03_mar_2014.zip CPU:i54469 OS:Ubuntu 15.04 执行CONFIGURE之前需要 unset JAVA_TOOL_OPTIONS configure执行成功后,运行下面语句报错了,具体错误请看标黄的部分 /Desktop/openjdk$ make CONF=linux-x86_64-normal-server-fastdebug Building 'linux-x86_64-normal-server-fastdebug' (matching CONF=linux-x86_64-normal-server-fastdebug) Building OpenJDK for target 'default' in configuration 'linux-x86_64-normal-server-fastdebug' ## Starting langtools ## Finished langtools (build time 00:00:00) ## Starting hotspot make[2]: warning: -jN forced in submake: disabling jobserver mode. INFO: ENABLE_FULL_DEBUG_SYMBOLS=1 INFO: ALT_OBJCOPY=/usr/bin/objcopy INFO: /usr/bin/objcopy cmd found so will create .debuginfo files. INFO: STRIP_POLICY=min_strip INFO: ZIP_DEBUGINFO_FILES=1 INFO: ENABLE_FULL_DEBUG_SYMBOLS=1 INFO: ALT_OBJCOPY=/usr/bin/objcopy INFO: /usr/bin/objcopy cmd found so will create .debuginfo files. INFO: STRIP_POLICY=min_strip INFO: ZIP_DEBUGINFO_FILES=1/usr/bin/make: invalid option -- '/'/usr/bin/make: invalid option -- 'a'/usr/bin/make: invalid option -- '/'/usr/bin/make: invalid option -- 'c'Usage: make [options] [target] ...Options: -b, -m Ignored for compatibility. -B, --always-make Unconditionally make all targets. -C DIRECTORY, --directory=DIRECTORY Change to DIRECTORY before doing anything. -d Print lots of debugging information. --debug[=FLAGS] Print various types of debugging information. -e, --environment-overrides Environment variables override makefiles. --eval=STRING Evaluate STRING as a makefile statement. -f FILE, --file=FILE, --makefile=FILE Read FILE as a makefile. -h, --help Print this message and exit. -i, --ignore-errors Ignore errors from recipes. -I DIRECTORY, --include-dir=DIRECTORY Search DIRECTORY for included makefiles. -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg. -k, --keep-going Keep going when some targets can't be made. -l [N], --load-average[=N], --max-load[=N] Don't start multiple jobs unless load is below N. -L, --check-symlink-times Use the latest mtime between symlinks and target. -n, --just-print, --dry-run, --recon Don't actually run any recipe; just print them. -o FILE, --old-file=FILE, --assume-old=FILE Consider FILE to be very old and don't remake it. -O[TYPE], --output-sync[=TYPE] Synchronize output of parallel jobs by TYPE. -p, --print-data-base Print make's internal database. -q, --question Run no recipe; exit status says if up to date. -r, --no-builtin-rules Disable the built-in implicit rules. -R, --no-builtin-variables Disable the built-in variable settings. -s, --silent, --quiet Don't echo recipes. -S, --no-keep-going, --stop Turns off -k. -t, --touch Touch targets instead of remaking them. --trace Print tracing information. -v, --version Print the version number of make and exit. -w, --print-directory Print the current directory. --no-print-directory Turn off -w, even if it was turned on implicitly. -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE Consider FILE to be infinitely new. --warn-undefined-variables Warn when an undefined variable is referenced. This program built for x86_64-pc-linux-gnu Report bugs to <bug-make@gnu.org> make[5]: *** [ad_stuff] Error 2 /home/dxt/Desktop/openjdk/hotspot/make/linux/makefiles/top.make:91: recipe for target 'ad_stuff' failed /home/dxt/Desktop/openjdk/hotspot/make/linux/Makefile:289: recipe for target 'fastdebug' failed make[4]: *** [fastdebug] Error 2 Makefile:216: recipe for target 'generic_build2' failed make[3]: *** [generic_build2] Error 2 Makefile:167: recipe for target 'fastdebug' failed make[2]: *** [fastdebug] Error 2 HotspotWrapper.gmk:44: recipe for target '/home/dxt/Desktop/openjdk/build/linux-x86_64-normal-server-fastdebug/hotspot/_hotspot.timestamp' failed make[1]: *** [/home/dxt/Desktop/openjdk/build/linux-x86_64-normal-server-fastdebug/hotspot/_hotspot.timestamp] Error 2 /home/dxt/Desktop/openjdk//make/Main.gmk:108: recipe for target 'hotspot-only' failed make: *** [hotspot-only] Error 2 dxt@dxt-All-Series:~/Desktop/openjdk$ pon dsl-provider Plugin rp-pppoe.so loaded.
怎么通过ping返回的值获得系统信息;什么系统,及系统的位数
package com; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class TimerExecPing { /** * @param args */ public static void ping(final String host) { String system = (String) (System.getProperty("os.name")).toLowerCase(); String command = ""; if (system.indexOf("xp") != -1 || system.indexOf("win") !=-1) { command += "ping win " + host; System.out.println(command); } else if (system.indexOf("linux") != -1) { command += "ping linux" + host; System.out.println(command); } else { command += "ping " + host; System.out.println(command); } TimerTask timerTask = new TimerTask() { public void run() { Process process; try { process = Runtime.getRuntime().exec("ping " + host); String result = ""; BufferedReader input = new BufferedReader( new InputStreamReader(process.getInputStream(), "gbk")); String line; while ((line = input.readLine()) != null) { result += line; // result=line.split(" "); System.out.println(line); } input.close(); } catch (IOException e) { e.printStackTrace(); } } }; Timer timer = new Timer(); timer.schedule(timerTask, new Date()); } public static void main(String[] args) { TimerExecPing pi=new TimerExecPing(); pi.ping("200.1.1.60"); } } 图为通过ping ip的结果,然后我怎么做。能给出代码最好
请教HttpURLConnection的返回码问题
发现有些跳转的网址,用jdk的HttpURLConnection类访问返回的响应不一样。比如http://dwz.cn/11ftOg这个链接: java代码很简单: ``` String requestUrl = "http://dwz.cn/11ftOg"; HttpURLConnection conn = null; try { URL url = new URL(requestUrl); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(300); conn.setReadTimeout(500); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); conn.connect(); int code = conn.getResponseCode(); System.out.println("+++++++ response code: " + code); } catch (IOException e) { System.out.println("+++++++ error:"+ e); } finally { if (conn != null) { conn.disconnect(); } } ``` 执行后输出: +++++++ > response code: 301 但是在浏览器访问抓包,在linux上curl访问都返回的是302: ``` ~> curl -I 'http://dwz.cn/11ftOg' HTTP/1.1 302 Found Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Origin,Accept,Content-Type,X-Requested-With Access-Control-Allow-Methods: POST,GET,PUT,PATCH,DELETE,HEAD Access-Control-Allow-Origin: Content-Type: text/html; charset=utf-8 Date: Tue, 18 Dec 2018 07:32:23 GMT Location: http://www.hzins.com/study/studytag/word-2820-205-9.html/?id=hz6 Set-Cookie: DWZID=71abaaa6daf9c9151434309799aacd30; Path=/; Domain=dwz.cn; Max-Age=31536000; HttpOnly ``` 哪位大神讲讲这是啥原因呢
读取xml报错testError on line 1 of document
定时任务读取xml文件时,会偶尔出现一个报错testError on line 1 of document :Premature en of file.Nested exception:Premature end of file 一个sftp传输工具读取一个文件夹里的xml文件,由于需要一直跑,所以写了个定时任务,在把jar包部署到linux下运行时,处理很多个之后会出现这个报错,然后重新单独把这个文件放进去的时候又能够正常解析。 这个解析xml文件的方法我按照百度的说法已经改过了,之前是用的SAXReader解析的,后来改的先获取文件内容存入缓存中,但是依然有这个问题,没有什么BOM头,因为是从服务器的一个文件夹里面去读取的xml文件,这个xml文件是只要生成了我就去读取,所以是个1秒读一次 不知道是不是定时任务有问题还是咋的了,已经想了各种办法依旧不行,出错的xml文件单独拿出来再跑依旧可以正常解析,很奇怪,求大神解决,如能解决的可以联系远程也行,必有重谢 报错信息 ![图片说明](https://img-ask.csdn.net/upload/201805/21/1526892582_442239.jpg) public class ReadFile { private static Logger logger = Logger.getLogger(ReadFile.class); public ReadFile() { } /** * 读取某个文件夹下的所有文件 */ public static boolean readfile(String filepath) throws FileNotFoundException, IOException { try { File file = new File(filepath); if (!file.isDirectory()) { System.out.println("文件"); System.out.println("path=" + file.getPath()); System.out.println("absolutepath=" + file.getAbsolutePath()); System.out.println("name=" + file.getName()); } else if (file.isDirectory()) { logger.info("读取文件夹成功"); String[] filelist = file.list(); for (int i = 0; i < filelist.length; i++) { File readfile = new File(filepath + File.separator + filelist[i]); logger.info("filepath:" + filepath); if (!readfile.isDirectory()) { logger.info("path=" + readfile.getPath()); logger.info("absolutepath=" + readfile.getAbsolutePath()); logger.info("name=" + readfile.getName()); } else if (readfile.isDirectory()) { readfile(filepath + File.separator + filelist[i]); } DataSourceXMLParse.parserXml(readfile.getAbsolutePath()); // 删除xml ReadFile.delFolder(readfile.getAbsolutePath()); } } } catch (FileNotFoundException e) { logger.info("readfile() Exception:" + e.getMessage()); } return true; } // 删除文件 // param folderPath 文件夹完整绝对路径 public static void delFolder(String folderPath) { try { String filePath = folderPath; filePath = filePath.toString(); String[] str = folderPath.split("/"); int len = str.length; String filename = str[len-1]; java.io.File myFilePath = new java.io.File(filePath); System.out.println("****************** folderPath = "+folderPath); System.out.println("****************** filePath = "+filePath); File dest_dir = new File("/home/d5000/test_file/in_back"); File dest = new File("/home/d5000/test_file/in_back/"+filename); if(!dest_dir.exists()){ dest_dir.mkdirs(); } myFilePath.renameTo(dest); // myFilePath.delete(); // 删除文件 } catch (Exception e) { e.printStackTrace(); System.out.println("****************** "+e.getCause()); } } public static void writeToFile(String context, String filePath, String filename) { System.out.println("congtext:" + context + " filePath" + filePath + "\n"); FileOutputStream fop = null; File file; try { file = new File(filePath + filename); if (!file.exists()) { file.createNewFile(); } fop = new FileOutputStream(file); byte[] contentInBytes = context.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (fop != null) { fop.close(); } } catch (IOException e) { logger.info(e.getMessage()); e.printStackTrace(); } } } public static void main(String[] args) { logger.info("**********开启启动监控系统图模审核消息文件夹"); Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); System.out.println(hour + ":" + minute + ":" + second + "\n"); TimerTask task = new TimerTask() { int nCountSuc = 0; @Override public void run() { try { boolean bRet = readfile(ReadProperties .get("LOCAL_cimsvgpath")); if (bRet) { nCountSuc++; } // Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); System.out.println(hour + ":" + minute + ":" + second + "\n"); if (hour == 23 && minute == 59 && second==59) { SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd");// 设置日期格式 String filename = df.format(new Date()) + ".txt"; // count写入文件 writeToFile(String.valueOf("收到总数:" + nCountSuc+"条, 发送总数"+nCountSuc), ReadProperties.get("SEND_AND_RECEIVE_PATH"), filename); // 初始化 nCountSuc = 0; } } catch (FileNotFoundException ex) { logger.info(ex.getMessage()); ex.printStackTrace(); } catch (IOException ex) { logger.info(ex.getMessage()); ex.printStackTrace(); } System.out.println("**********正在读取文件"); } }; Timer timer = new Timer(); long delay = 0; long intevalPeriod = 1 * 1000; timer.scheduleAtFixedRate(task, delay, intevalPeriod); } } ``` 下面代码是读取xml及一些处理逻辑 ``` public static void parserXml(String contextPath) { logger.info("**********开始解析XML文件"); // File inputXml = new File(contextPath); // SAXReader saxReader = new SAXReader(); try { // Document document = saxReader.read(inputXml); StringBuffer content = new StringBuffer(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(contextPath),"GBK")); String line = null; while((line = br.readLine()) != null ){ content.append(line+"\n"); } br.close(); Document document = DocumentHelper.parseText(content.toString()); //根节点 Element root = document.getRootElement(); //遍历 map.clear(); map = listNodes2(root); listNodes(map); } catch (Exception e) { logger.info("test" + e.getMessage()); e.printStackTrace(); } logger.info("**********解析XML文件完成"); } ```
定时器任务 timer.schedule为什么每次任务都晚几秒执行,还有到第二天0点的时候都晚50多分钟?
[color=red]//创建一个定时器,在下一小时的第30分种第一次执行,然后每小时执行一次。[/color] private void startCollegeIPDay(){ Timer timer = new Timer(true); long day = 24 * 60 * 60 * 1000; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 55); calendar.set(Calendar.SECOND, 0); timer.schedule(new CollegeDayIPTask(), calendar.getTime(), day); } [color=red]//任务task[/color] public class CollegeIPTask extends TimerTask { public CollegeIPTask() { } @Override public void run() { try{ //业务逻辑 }catch (Exception e) { e.printStackTrace(); } } } [color=red]第一次任务没问题,但是从第二次开始没次任务都晚几秒执行,还有到第二天0点的时候直接0点50多分钟才执行,1点的时候直接就2点多才执行,怎么回事?[/color]
Comet4j推送页面console报错
最近在做一个页面信息推送的需求。其实很简单,就是前台页面在不刷新的情况下,会定时得到后台推送的数据来更新页面,我使用的是comet4j。但是在使用过程中遇到一些问题,百度很多,也没有相关资料。所以发帖求助。 问题:如图,在每次推送的时候页面console就报这个错误 ![图片说明](https://img-ask.csdn.net/upload/201711/21/1511246476_818568.png) 说明下,我jdk用的1.7,server.xml配置也已更改。有的时候可以推送成功,有的时候又会包这个错。在本地还好,基本都能成功,尤其是在linux上,就出错频率高。下面贴出我们推送的部分关键代码: 后台java代码如下: ``` @Override public boolean handleEvent(ConnectEvent event) { // TODO Auto-generated method stub final CometConnection conn = event.getConn(); HttpServletRequest request = conn.getRequest(); HttpServletResponse response = conn.getResponse(); //获取当前用户 User activeUser = ActiveUser.getInstance().getLoginUserOfSession(request, response); int userid = activeUser.getUserid(); //将每一次事件时的用户id和事件存入缓存 CacheManager.putContent(event, userid, EXPIRED_AFTER_ONE_HOUR); return true; } @Override public void contextInitialized(ServletContextEvent sce) { // TODO Auto-generated method stub // CometContext : Comet4J上下文,负责初始化配置、引擎对象、连接器对象、消息缓存等。 CometContext cc = CometContext.getInstance(); // 注册频道,即标识哪些字段可用当成频道,用来作为向前台传送数据的“通道” cc.registChannel(CHANNEL1); cc.registChannel(CHANNEL2); cc.registChannel(CHANNEL3); cc.registChannel(CHANNEL4); cc.registChannel(CHANNEL5); cc.registChannel(CHANNEL6); cc.registChannel(CHANNEL7); cc.registChannel(CHANNEL8); cc.registChannel(CHANNEL9); cc.registChannel(CHANNEL10); cc.registChannel(CHANNEL11); //添加监听器 CometEngine engine = CometContext.getInstance().getEngine(); engine.addConnectListener(this); //初始化时开启推送 pushThread = new Thread(new SendToClientThread()); pushThread.start(); } //推送到指定用户和指定频道 engine.sendTo(CHANNEL1,engine.getConnection(preconnid),JSON.toJSONString(personMsgList)); engine.sendTo(CHANNEL2,engine.getConnection(preconnid),JSON.toJSONString(personInboxList)); engine.sendTo(CHANNEL3,engine.getConnection(preconnid), JSON.toJSONString(personOutboxList)); engine.sendTo(CHANNEL4,engine.getConnection(preconnid), JSON.toJSONString(groupMsgList)); engine.sendTo(CHANNEL5,engine.getConnection(preconnid), JSON.toJSONString(groupInboxList)); engine.sendTo(CHANNEL6,engine.getConnection(preconnid), JSON.toJSONString(groupOutboxList)); engine.sendTo(CHANNEL7,engine.getConnection(preconnid), JSON.toJSONString(directMsgList)); engine.sendTo(CHANNEL8,engine.getConnection(preconnid), JSON.toJSONString(directGroupMsgList)); engine.sendTo(CHANNEL9,engine.getConnection(preconnid), JSON.toJSONString(directOutboxList)); engine.sendTo(CHANNEL10,engine.getConnection(preconnid), JSON.toJSONString(dataMap)); engine.sendTo(CHANNEL11,engine.getConnection(preconnid), JSON.toJSONString(groupParMap)); ``` 页面接收如下: JS.Engine.on({ res3 : function(data) { if(data != null) { //console.log("PersonMsgOutbox页面解析前的数据:"+data); var res = eval('('+data+')'); //console.log("PersonMsgOutbox页面解析后的数据:"+res); var str = "",msgno = "",username = "",status = "",msgtext = "",stime = "",atime = "",ackby = "",btn1 = "" ,btn2= ""; for ( var i = 0 ; i < res.length ; i++) { switch (res[i].status) { case 0: status = "Pending"; break; case 1: status = "Sending"; break; case 2: status = "PartialComplete"; break; case 3: status = "Complete"; break; case 4: status = "Fail"; break; case 5: status = "Aborted"; break; case 6: status = "NoDevice"; break; case 7: status = "NoProfile"; break; case 8: status = "NoPattern"; break; case 9: status = "NoSequence"; break; case 10: status = "AccountDisable"; break; case 11: status = "Schedule"; break; } if(res[i].isresend == 0) { btn1 = "<button class='btn btn-info' type='button' style='margin-left:4px;' onclick='ReplyPersonMsg(\""+res[i].mrid+"\")'>Ack</button>"; } else { btn1 = "<button class='btn btn-info' type='button' style='margin-left:4px;' disabled='disabled'>Ack</button>"; } if(res[i].status != 5) { btn2 = "<button class='btn btn-info' type='button' style='margin-left:4px;' onclick='editMsg(\""+res[i].msgid+"\")'>Edit</button>"+ "<button class='btn btn-danger' type='button' style='margin-left:4px;' onclick='stopMsg(\""+res[i].mrid+"\")'>Abort</button>"; } else { btn2 = "<button class='btn btn-info' type='button' style='margin-left:4px;' disabled='disabled'>Edit</button>"+ "<button class='btn btn-danger' type='button' style='margin-left:4px;' disabled='disabled'>Abort</button>"; } msgno = res[i].msgno == null ? "" : res[i].msgno; username = res[i].username == null ? "" : res[i].username; msgtext = res[i].msgtext == null ? "" : res[i].msgtext; //dateFtt("yyyy-MM-dd hh:mm:ss",new Date(res[i].scheduletime)) stime = res[i].scheduletime == null ? "" : res[i].scheduletime; atime = res[i].acktime == null ? "" : dateFtt("yyyy-MM-dd hh:mm:ss",new Date(res[i].acktime)); ackby = res[i].ackby == null ? "" : res[i].ackby; str += "<tr>"+ "<td>"+msgno+"</td>"+ "<td>"+username+"</td>"+ "<td>"+status+"</td>"+ "<td>"+msgtext+"</td>"+ "<td>"+stime+"</td>"+ "<td>"+atime+"</td>"+ "<td>"+ackby+"</td>"+ "<td><button class='btn btn-info' type='button' id='updateDept' onclick='WatchMsgDetail(\""+res[i].mrid+"\",\""+res[i].userid+"\")'>Detail</button>"+btn1+btn2+"</td>"+ "</tr>"; } $("#outboxBody").html(str); } } }); JS.Engine.start('conn'); ``` ``` 请有经验的大佬指点迷津。。。如有什么需要补充,尽情提出!!谢谢
终于明白阿里百度这样的大公司,为什么面试经常拿ThreadLocal考验求职者了
点击上面↑「爱开发」关注我们每晚10点,捕获技术思考和创业资源洞察什么是ThreadLocalThreadLocal是一个本地线程副本变量工具类,各个线程都拥有一份线程私有的数
win10系统安装教程(U盘PE+UEFI安装)
一、准备工作 u盘,电脑一台,win10原版镜像(msdn官网) 二、下载wepe工具箱  极力推荐微pe(微pe官方下载) 下载64位的win10 pe,使用工具箱制作启动U盘打开软件,   选择安装到U盘(按照操作无需更改) 三、重启进入pe系统   1、关机后,将U盘插入电脑 2、按下电源后,按住F12进入启动项选择(技嘉主板是F12)     选择需要启
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小人工智障。 思路可以运用在不同地方,主要介绍的是思路。
Nginx 软件层面加强Nginx性能优化的面试问答和解决方案
Nginx 软件层面加强Nginx性能优化的面试问答和解决方案 去年我去爱卡汽车面试PHP,一轮和二轮面的都不错,在三轮面到Nginx的时候很多问题当时不知道怎么回答,确实没有深入学习过,花了一段时间的学习,终于能解答Nginx高性能优化的问题了,10月24号为了获得程序员勋章,发布了半个优化笔记,浏览到了1000+,受到这个鼓舞,我抽时间在仔细整理下关于Nginx性能优化的问题,我们从软件说起。...
【管理系统课程设计】美少女手把手教你后台管理
【文章后台管理系统】URL设计与建模分析+项目源码+运行界面 栏目管理、文章列表、用户管理、角色管理、权限管理模块(文章最后附有源码) 1. 这是一个什么系统? 1.1 学习后台管理系统的原因 随着时代的变迁,现如今各大云服务平台横空出世,市面上有许多如学生信息系统、图书阅读系统、停车场管理系统等的管理系统,而本人家里就有人在用烟草销售系统,直接在网上完成挑选、购买与提交收货点,方便又快捷。 试想,若没有烟草销售系统,本人家人想要购买烟草,还要独自前往药...
11月19日科技资讯|华为明日发布鸿蒙整体战略;京东宣告全面向技术转型;Kotlin 1.3.60 发布
「极客头条」—— 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧。扫描上方二维码进入 CSDN App 可以收听御姐萌妹 Style 的人工版音频哟。 一分钟速览新闻点! 6G 专家组成员:速率是 5G 的 10 至 100 倍,预计 2030 年商用 雷军:很多人多次劝我放弃WPS,能坚持下来并不是纯粹的商业决定 ...
C语言魔塔游戏
很早就很想写这个,今天终于写完了。 游戏截图: 编译环境: VS2017 游戏需要一些图片,如果有想要的或者对游戏有什么看法的可以加我的QQ 2985486630 讨论,如果暂时没有回应,可以在博客下方留言,到时候我会看到。 下面我来介绍一下游戏的主要功能和实现方式 首先是玩家的定义,使用结构体,这个名字是可以自己改变的 struct gamerole { char n
化繁为简 - 腾讯计费高一致TDXA的实践之路
导语:腾讯计费是孵化于支撑腾讯内部业务千亿级营收的互联网计费平台,在如此庞大的业务体量下,腾讯计费要支撑业务的快速增长,同时还要保证每笔交易不错账。采用最终一致性或离线补...
Python爬虫爬取淘宝,京东商品信息
小编是一个理科生,不善长说一些废话。简单介绍下原理然后直接上代码。 使用的工具(Python+pycharm2019.3+selenium+xpath+chromedriver)其中要使用pycharm也可以私聊我selenium是一个框架可以通过pip下载 pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple/ 
Java学习笔记(七十二)—— Cookie
概述 会话技术: 会话:一次会话中包含多次请求和响应 一次会话:浏览器第一次给服务器发送资源请求,会话建立,直到有一方断开为止 功能:在一次会话的范围内的多次请求间,共享数据 方式: 客户端会话技术:Cookie,把数据存储到客户端 服务器端会话技术:Session,把数据存储到服务器端 Cookie 概念:客户端会话技术,将数据存储到客户端 快速入门: 使用步骤: 创建C
Java工作4年来应聘要16K最后没要,细节如下。。。
前奏: 今天2B哥和大家分享一位前几天面试的一位应聘者,工作4年26岁,统招本科。 以下就是他的简历和面试情况。 基本情况: 专业技能: 1、&nbsp;熟悉Sping了解SpringMVC、SpringBoot、Mybatis等框架、了解SpringCloud微服务 2、&nbsp;熟悉常用项目管理工具:SVN、GIT、MAVEN、Jenkins 3、&nbsp;熟悉Nginx、tomca
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆  每天早上8:30推送 作者| Mr.K   编辑| Emma 来源| 技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯
程序员该看的几部电影
##1、骇客帝国(1999) 概念:在线/离线,递归,循环,矩阵等 剧情简介: 不久的将来,网络黑客尼奥对这个看似正常的现实世界产生了怀疑。 他结识了黑客崔妮蒂,并见到了黑客组织的首领墨菲斯。 墨菲斯告诉他,现实世界其实是由一个名叫“母体”的计算机人工智能系统控制,人们就像他们饲养的动物,没有自由和思想,而尼奥就是能够拯救人类的救世主。 可是,救赎之路从来都不会一帆风顺,到底哪里才是真实的世界?
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东
@程序员,如何花式构建线程?
作者 |曾建责编 | 郭芮出品 | CSDN(ID:CSDNnews)在项目和业务的开发中,我们难免要经常使用线程来进行业务处理,使用线程可以保证我们的业务在相互处理之间可以保证原子性...
破14亿,Python分析我国存在哪些人口危机!
2020年1月17日,国家统计局发布了2019年国民经济报告,报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏,但是很多人并没有看到我国复杂的人口问题:老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧! 一、背景 1.人口突破14亿 2020年1月17日,国家统计局发布了 2019年国民经济报告 ,报告中指出:年末中国大陆总人口(包括31个
强烈推荐10本程序员在家读的书
很遗憾,这个鼠年春节注定是刻骨铭心的,新型冠状病毒让每个人的神经都是紧绷的。那些处在武汉的白衣天使们,尤其值得我们的尊敬。而我们这些窝在家里的程序员,能不外出就不外出,就是对社会做出的最大的贡献。 有些读者私下问我,窝了几天,有点颓丧,能否推荐几本书在家里看看。我花了一天的时间,挑选了 10 本我最喜欢的书,你可以挑选感兴趣的来读一读。读书不仅可以平复恐惧的压力,还可以对未来充满希望,毕竟苦难终
Linux自学篇——linux命令英文全称及解释
man: Manual 意思是手册,可以用这个命令查询其他命令的用法。 pwd:Print working directory 显示当前目录 su:Swith user 切换用户,切换到root用户 cd:Change directory 切换目录 ls:List files 列出目录下的文件 ps:Process Status 进程状态 mk
Python实战:抓肺炎疫情实时数据,画2019-nCoV疫情地图
文章目录1. 前言2. 数据下载3. 数据处理4. 数据可视化 1. 前言 今天,群里白垩老师问如何用python画武汉肺炎疫情地图。白垩老师是研究海洋生态与地球生物的学者,国家重点实验室成员,于不惑之年学习python,实为我等学习楷模。先前我并没有关注武汉肺炎的具体数据,也没有画过类似的数据分布图。于是就拿了两个小时,专门研究了一下,遂成此文。 2月6日追记:本文发布后,腾讯的数据源多次变更u
智力题(程序员面试经典)
NO.1  有20瓶药丸,其中19瓶装有1克/粒的药丸,余下一瓶装有1.1克/粒的药丸。给你一台称重精准的天平,怎么找出比较重的那瓶药丸?天平只能用一次。 解法 有时候,严格的限制条件有可能反倒是解题的线索。在这个问题中,限制条件是天平只能用一次。 因为天平只能用一次,我们也得以知道一个有趣的事实:一次必须同时称很多药丸,其实更准确地说,是必须从19瓶拿出药丸进行称重。否则,如果跳过两瓶或更多瓶药
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ......
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!
2020年的1月,我辞掉了我的第一份工作
其实,这篇文章,我应该早点写的,毕竟现在已经2月份了。不过一些其它原因,或者是我的惰性、还有一些迷茫的念头,让自己迟迟没有试着写一点东西,记录下,或者说是总结下自己前3年的工作上的经历、学习的过程。 我自己知道的,在写自己的博客方面,我的文笔很一般,非技术类的文章不想去写;另外我又是一个还比较热衷于技术的人,而平常复杂一点的东西,如果想写文章写的清楚点,是需要足够...
别低估自己的直觉,也别高估自己的智商
所有群全部吵翻天,朋友圈全部沦陷,公众号疯狂转发。这两周没怎么发原创,只发新闻,可能有人注意到了。我不是懒,是文章写了却没发,因为大家的关注力始终在这次的疫情上面,发了也没人看。当然,我...
Java坑人面试题系列: 包装类(中级难度)
Java Magazine上面有一个专门坑人的面试题系列: https://blogs.oracle.com/javamagazine/quiz-2。 这些问题的设计宗旨,主要是测试面试者对Java语言的了解程度,而不是为了用弯弯绕绕的手段把面试者搞蒙。 如果你看过往期的问题,就会发现每一个都不简单。 这些试题模拟了认证考试中的一些难题。 而 “中级(intermediate)” 和 “高级(ad
Spring Boot 2.x基础教程:使用JdbcTemplate访问MySQL数据库
在第2章节中,我们介绍了如何通过Spring Boot来实现HTTP接口,以及围绕HTTP接口相关的单元测试、文档生成等实用技能。但是,这些内容还不足以帮助我们构建一个动态应用的服务端程序。不论我们是要做App、小程序、还是传统的Web站点,对于用户的信息、相关业务的内容,通常都需要对其进行存储,而不是像第2章节中那样,把用户信息存储在内存中(重启就丢了!)。 对于信息的存储,现在已经有非常非常多...
基于Python的人脸自动戴口罩系统
目录 1、项目背景 2、页面设计 3、器官识别 4、退出系统 1、项目背景 2019年新型冠状病毒感染的肺炎疫情发生以来,牵动人心,举国哀痛,口罩、酒精、消毒液奇货可居。 抢不到口罩,怎么办?作为技术人今天分享如何使用Python实现自动戴口罩系统,来安慰自己,系统效果如下所示: 本系统的实现原理是借助 Dlib模块的Landmark人脸68个关键点检测库轻松识别出人脸五官
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。   再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。   下文是原回答,希望能对你能有所启发。   如果我说,这个世界上人真的分三六九等,
节后首个工作日,企业们集体开晨会让钉钉挂了
By 超神经场景描述:昨天 2 月 3 日,是大部分城市号召远程工作的第一天,全国有接近 2 亿人在家开始远程办公,钉钉上也有超过 1000 万家企业活跃起来。关键词:十一出行 人脸...
Java基础知识点梳理
Java基础知识点梳理 摘要: 虽然已经在实际工作中经常与java打交道,但是一直没系统地对java这门语言进行梳理和总结,掌握的知识也比较零散。恰好利用这段时间重新认识下java,并对一些常见的语法和知识点做个总结与回顾,一方面为了加深印象,方便后面查阅,一方面为了学好java打下基础。 Java简介 java语言于1995年正式推出,最开始被命名为Oak语言,由James Gosling(詹姆
jQuery实现高仿QQ音乐
几个实现的效果看视频吧: bandicam 2020-02-05 16-28-20-127 动图很是不清楚 github地址奉上:https://github.com/tangmusenLiu/Large-warehouse https://github.com/tangmu
相关热词 c#导入fbx c#中屏蔽键盘某个键 c#正态概率密度 c#和数据库登陆界面设计 c# 高斯消去法 c# codedom c#读取cad文件文本 c# 控制全局鼠标移动 c# temp 目录 bytes初始化 c#
立即提问