• [技术干货] RDS for MySQL在启用了SSL验证连接功能后,导致代码(php/java/python)等连接数据库失败解决方法
    问题描述用户开启了SSL验证连接功能,使用代码执行SQL连接数据库出现如下报错:故障分析用户开启了SSL连接功能,只能使用SSL连接方式,不能使用普通连接方式。解决方案开启SSL验证连接功能,使用SSL连接方式连接数据库,请参考SSL连接方式。关闭SSL验证连接功能,使用普通连接方式连接数据库,请参考普通连接方式。
  • [技术干货] 请问华为的app engine是基于模型驱动架构(MDA)而设计和开发的吗?是基于JAVA系的MDA吗?
    请问华为的app engine是基于模型驱动架构(MDA)而设计和开发的吗?是基于JAVA系的MDA吗?
  • [技术干货] 几款Java开发者必备常用的工具,准点下班不在话下
     摘要:一问一答的形式轻松学习掌握java工具。以一问一答的形式学习java工具Q:检查内存泄露的工具有?A: jmap生成dump转储文件,jhat可视化查看。Q:某进程CPU使用率一直占满,用什么工具可以排查?A:top -Hp pid找到最占CPU的线程然后jstack来查找那个线程此时所处的堆栈,确定问题发生位置。§ 各工具详细介绍§ jstack全称: JVM Stack Trance作用: 查看某个java进程的堆栈情况, 可用于确认死锁、IO等待、死循环等问题。命令用法:jstack pid查看死锁例子如下图,找到wait的lock和已被锁的lock                                                            查看等待IO例子:§ jstat全称:作用:查看进程中内存使用情况,但只能给出一些简单统计数据统计加载了多少类以及占用空间 jstat -class pid统计编译了多少文件 jstat -compiler 10Q: jstat -gcutil {pid} 2000 可以每隔2秒,对pid进程打印内存使用统计信息。gcutil的输出如下里面哪个百分比如果长期处于99%-100%会有OMM风险?(OutOfMemoryError)A:如果E和O即新生代、老年代内存区一直都处于满的状态,则很有可能会引发OMM风险。就像下面这个。§ jmap全称: JVM Memory Map作用:生成进程的内存堆快照当需要看一下进程里是什么东西占用了过多内存时, 可以用jmap打印一下堆快照。命令用法:打印堆快照: jmap -dump:file=./dumpfile.dump 进程pid查看特定类所占用的情况: jmap -histo:live 进程pid | grep 类名Q: 用jmap检查内存泄漏实例我分了3次,每个1h调用jmap查看进程的内存实例,查看该时刻各对象数量第一次查看情况如下:第二次隔了2各小时,查看情况如下:请问哪个对象可能有内存泄漏风险?A:ObjectA可能有泄露, 因为他的对象数量增加最快,说明对象一直在增加且很多无法进行gc释放。§ jhat全称: JVM Heap Analysis Tool和jmap配合, 可以解析jmap生成的堆快照, 支持生成1个web进程供我们分析和查看。命令用法:jhat -J-Xmx515M dumpfile.dump此时就会启动1个webServer,然后我们去访问就行了§ jdb全称:Java Debugger作用:用来对core文件和正在运行的Java进程进行实时地调试,类似于c++里的gdb常见用法:启动进程并调试: jdb -classpath . Test至二级调试某进程: jdb -attach 8000 -sourcepath /Users/wefit/Development/study/java/jtest/src/§ jcmd作用:多功能的工具,可以用它来导出堆、查看Java进程、导出线程信息、执行GC、还可以进行采样分析,可以理解为1个性能调优时用的工具。常见命令:查看 当前机器上所有的 jvm 进程信息: jcmd -l查看指定进程的性能统计信息: jcmd pid PerfCounter.print列出当前运行的 java 进程可以执行的操作: jcmd PID help查看线程堆栈信息: jcmd PID Thread.print查看堆内存信息: jcmd PID GC.heap_dump FILE_NAME§ jps简单记法: JVM process status全名:Java Virtual Machine Process Status Tool作用: 显示 当前系统用户 的 所有 Java进程情况及其进程号常用命令:查看进程jvm参数: jps -v输出程序main class的完整package名或程序的jar文件完整路径名: jps -l输出传递给main方法的参数: jps -m§ jinfojvm infomation作用:和jps功能类似, 但是支持根据指定pis查看指定进程可以查看JVM参数、系统参数、调整jvm参数但不支持查看java程序的内存使用情况§ javap把java字节码文件反汇编为Java源码文件。§ javacjava编译工具javac的执行过程:
  • [技术干货] 2020-12-18:java和go,并发控制有哪几种方式?
    2020-12-18:java和go,并发控制有哪几种方式?#福大大架构师每日一题#
  • [技术干货] 2020-12-17:java和go,如何高效的拼接字符串?
    2020-12-17:java和go,如何高效的拼接字符串?#福大大架构师每日一题#
  • 学习java
    里面还有Java的初学者视频,很不错。
  • [开发应用] GaussDB 200当游标作为存储过程的返回值时,JAVA调用该存储过程,如何获取结果集?
        报错内容: Found multiple occurrences of org.json.JSONObject on the class path:jar:file:/D:/mvn_repository/org/json/json/20180813/json-20180813.jar!/org/json/JSONObject.classjar:file:/D:/mvn_repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.classYou may wish to exclude one of them to ensure predictable runtime behavior2020-12-14 16:50:22,071 [main] DEBUG [com.huawei.it.finioc.dao.IFiniocGaussDao.finiocGaussFunNewTest] ==>  Preparing: {call DWRSALES.proc_test_lyt( ?, ?, ?, ?) } 2020-12-14 16:50:22,081 [main] DEBUG [com.huawei.it.finioc.dao.IFiniocGaussDao.finiocGaussFunNewTest] ==> Parameters: 1(String), 1(String), YYY(String)org.springframework.jdbc.BadSqlGrammarException: ### Error querying database.  Cause: com.huawei.gauss200.jdbc.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=1111 however type java.sql.Types=-10 was registered.### The error may exist in file [D:\Idea\Jalor6\cnbgioc_develop\om.impl\target\classes\com\huawei\it\finioc\dao\IFiniocGaussDao.xml]### The error may involve com.huawei.it.finioc.dao.IFiniocGaussDao.finiocGaussFunNewTest-Inline### The error occurred while setting parameters### SQL: {call DWRSALES.proc_test_lyt(       ?,       ?,       ?,       ?)    }### Cause: com.huawei.gauss200.jdbc.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=1111 however type java.sql.Types=-10 was registered.; bad SQL grammar []; nested exception is com.huawei.gauss200.jdbc.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=1111 however type java.sql.Types=-10 was registered.at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159)at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)at com.huawei.it.finioc.dao.FiniocGaussDaoTest.finiocGaussFunNewTest(FiniocGaussDaoTest.java:50)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.lang.reflect.Method.invoke(Method.java:498)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)Caused by: com.huawei.gauss200.jdbc.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=1111 however type java.sql.Types=-10 was registered.at com.huawei.gauss200.jdbc.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:473)at com.huawei.gauss200.jdbc.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:415)at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)at org.apache.ibatis.executor.statement.CallableStatementHandler.query(CallableStatementHandler.java:68)at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.lang.reflect.Method.invoke(Method.java:498)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)... 22 moreDisconnected from the target VM, address: '127.0.0.1:49938', transport: 'socket'Process finished with exit code -1  
  • [技术干货] java实现文件上传功能(下)
    public ServletFileUpload getServletFileUpload(DiskFileItemFactory factory) { ServletFileUpload upload = new ServletFileUpload(factory); //监听文件上传进度 upload.setProgressListener(new ProgressListener() {  @Override  public void update(long uploaded, long totalSize, int i) {  System.out.println("已上传:"+(uploaded*100)/totalSize+"%");  } }); upload.setHeaderEncoding("UTF-8");//乱码处理 upload.setFileSizeMax(1024 * 1024 * 10);//设置单个文件的最大值10M upload.setSizeMax(1024 * 1024 * 100);//设置总共能上传文件的最大值100M return upload; }  public String uploadParseRequest(ServletFileUpload upload, HttpServletRequest req, String uploadPath) throws FileUploadException, IOException { String msg = ""; //把前端请求解析,封装成一个List对象 List<FileItem> fileItems = upload.parseRequest(req); for (FileItem fileItem : fileItems) {  if (fileItem.isFormField()) {//判断上传的文件是普通的表单还是带文件的表单  String name = fileItem.getName();//前端表单控件的name:username  String value = fileItem.getString("UTF-8");//乱码处理  System.out.println(name + ":" + value);  } else {//判断为上传的文件  //==================处理文件=====================  String uploadFileName = fileItem.getName();//前端表单控件的name  System.out.println("上传的文件名:" + uploadFileName);  if (uploadFileName.trim().equals("") || uploadFileName == null) {//可能存在不合法的情况   continue;  }  String fileName = uploadFileName.substring(uploadFileName.lastIndexOf("/") + 1);//文件名  String fileExtName = uploadFileName.substring(uploadFileName.lastIndexOf(".") + 1);//文件后缀名  System.out.println("文件名:" + fileName + "--文件后缀:" + fileExtName);  //==================存放地址==================  String uuidPath = UUID.randomUUID().toString();  //文件存储的真实路径  String realPath = uploadPath + "/" + uuidPath;  System.out.println("文件上传到的位置:"+realPath);  //给每个文件创建一个文件夹  File realPathFile = new File(realPath);  if (!realPathFile.exists()) {//如果文件夹不存在,则创建一个   realPathFile.mkdir();  }  //==================文件传输==================  //获得文件上传的流  InputStream inputStream = fileItem.getInputStream();  //创建一个文件输出流  FileOutputStream fileOutputStream = new FileOutputStream(realPath + "/" + fileName);  //创建一个缓冲区  byte[] buffer = new byte[1024 * 1024];  //判断读取是否完毕  int len = 0;  while ((len = inputStream.read(buffer)) > 0) {   fileOutputStream.write(buffer, 0, len);  }  //关闭流  fileOutputStream.close();  inputStream.close();  msg = "上传成功";  fileItem.delete();//上传成功,清除临时文件  } } return msg;}文件上传的注意事项1、为保证服务器安全,上传的文件应该放在外界无法直接访问的目录下,例如放在WEB-INF目录下。2、为了防止文件覆盖的现象,要为上传的文件产生一个唯一的文件名(可以为每一个上传的文件增加一个uuid或时间戳为名的文件夹)3、限制上传文件的最大值4、限制上传文件的类型,在收到上传文件时,判断其后缀名是否合法,是否为自己限制的类型
  • [技术干货] java实现文件上传功能(上)
    本文实例为大家分享了java实现文件上传的具体代码,供大家参考,具体内容如下一、文件上传准备工作对于文件上传,浏览器在上传的过程中将文件以流的形式提交到服务器。可以选择apache的commons-fileupload包作为文件上传组件,commons-fileupload包依赖于commons-io包。可以在Maven导入该commons-fileupload包,Maven会帮我们导入依赖的jar包commons-io。12345<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.3</version></dependency>二、文件上传的主要步骤创建diskFileItemFactory对象,处理文件上传路径或者大小限制通过diskFileItemFactory对象作为ServletFileUpload类的参数,创建ServletFileUpload对象处理上传的文件三、代码实现在文件上传时,表单一定要加enctype=“multipart/form-data” 。只有使用enctype=“multipart/form-data”,表单才会把文件的内容编码到HTML请求中。默认enctype=“application/x-www-form-urlencoded”,表单的内容会按URL规则编码。而enctype="multipart/form-data"不对字符编码。在使用包含文件上传控件的表单时,必须使用该值。method也一定要使用post请求。123456<form action="/file.do" enctype="multipart/form-data" method="post"> <p>上传用户:<input type="text" name="username"></p> <p><input type="file" name="file1"></p> <p><input type="file" name="file2"></p> <p><input type="submit">|<input type="reset"></p></form>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //判断上传的是普通表单还是带文件的表单 if (!ServletFileUpload.isMultipartContent(req)) {  return; } //创建上传文件保存的地址,一般创建在WEB-INF目录下,用户无法直接访问该目录下的文件 String uploadPath = this.getServletContext().getRealPath("/WEB-INF/upload"); File uploadFile = new File(uploadPath); //如果文件夹不存在,则创建一个 if (!uploadFile.exists()) {  uploadFile.mkdir(); }  //创建上传大文件的临时地址,一般几天后自动删除,用户可以手动删除或者转为永久文件 // 一般创建在WEB-INF目录下,用户无法直接访问该目录下的文件 String tempPath = this.getServletContext().getRealPath("/WEB-INF/temp"); File tempFile = new File(tempPath); //如果文件夹不存在,则创建一个 if (!tempFile.exists()) {  tempFile.mkdir(); }  //1.创建diskFileItemFactory对象,处理文件上传路径或者大小限制 DiskFileItemFactory factory = getDiskFileItemFactory(tempFile);  //2.获取ServletFileUpload ServletFileUpload upload = getServletFileUpload(factory);  //3.处理上传的文件 try {  String msg = uploadParseRequest(upload, req, uploadPath);  //转发  req.setAttribute("msg",msg);  req.getRequestDispatcher("info.jsp").forward(req, resp); } catch (FileUploadException e) {  e.printStackTrace(); } }   public DiskFileItemFactory getDiskFileItemFactory(File file) { DiskFileItemFactory factory = new DiskFileItemFactory(); //创建一个缓存区,当上传文件大于设置的缓存区时,将该文件放到临时目录 factory.setSizeThreshold(1024 * 1024);//缓存区大小为1M factory.setRepository(file);//临时目录 return factory; }
  • [技术干货] 2020-12-12:现场写代码,把CPU打满,java和go都行,并解释为什么。
    2020-12-12:现场写代码,把CPU打满,java和go都行,并解释为什么。#福大大架构师每日一题#
  • [技术干货] 使用Shell脚本如何启动/停止Java的jar程序
    启动脚本:start_upload.sh123#!/bin/shnohup java -jar UploadSchedule.jar >> /usr/local/tomcat9/webapps/upload-to-oss/nohup_upload.out 2>&1 &echo $! > /var/run/UploadSchedule.pid 启动脚本说明:1、开启后台执行,并将程序产生的日志文件写入out文件;2、将当前进程id写入/var/run/UploadSchedule.pid,以供在停止脚本中使用此pid来停止当前进程。停止脚本:stop_upload.sh123#!/bin/shPID=$(cat /var/run/UploadSchedule.pid)kill -9 $PID 停止脚本说明:1、首先获取进程id;2、然后杀掉该进程。文件切分:split_nohup.sh程序不中断,一直在后台运行,那么产生的log也会持续输出到out问价,导致out文件越来越大。当需要根据out文件进行一些日志查找的时候,非常不方便。所以定期对out文件进行切分,按日期将当日out文件切分成若干小文件,从而方便处理及错误查找定位。12345678910#!/bin/bashlog_path=/usr/local/tomcat9/webapps/upload-to-oss if [ -f "$log_path/nohup_upload.out" ];thencurrent_date=`date -d "-1 day" "+%Y%m%d"`cp $log_path/nohup_upload.out $log_path/nohup_upload_${current_date}.outcat /dev/null > $log_path/nohup_upload.outsplit -b 5242880 -d -a 4 $log_path/nohup_upload_${current_date}.out $log_path/nohup_upload_${current_date}_rm -rf $log_path/nohup_upload_${current_date}.outfi切分脚本说明:1、如果out文件存在,将nohup_upload.out文件复制一份,命名为nohup_upload_当前日期(比如nohup_upload_20200328.out);2、将nohup_upload.out文件清空;3、对nohup_upload_20200328.out文件进行切分,切分后的文件命名格式为nohup_upload_20200328_0001,nohup_upload_20200328_0002;-b 指定每个小文件的大小(单位byte)-d 以数字作为后缀-a 指定后缀的长度4、将原文件(nohup_upload_20200328.out)删除。执行开启/停止命令12345# 启动./start_upload.sh # 停止./stop_upload.sh一些后台运行的小知识&和nohup区别:&的意思是在后台运行。意思是说, 当你在执行 ./start_upload.sh & 的时候, 即使你用Ctrl + C, 那么start_upload.sh照样运行(因为对SIGINT信号免疫)。 但是要注意, 如果你直接关掉Shell后, 那么, start_upload.sh进程同样消失。 因为对SIGHUP信号不免疫。nohup的意思是忽略SIGHUP信号, 所以当运行nohup ./start_upload.sh的时候, 关闭Shell,start_upload.sh进程还是存在的(对SIGHUP信号免疫)。 但是如果你直接在Shell中用Ctrl + C, 那么,start_upload.sh进程也是会消失的(因为对SIGINT信号不免疫)所以,要让进程真正不受Shell中Ctrl + C和Shell关闭的影响, 就用nohup和&同时用。
  • [技术干货] java中分段上传,设置整个文件的MD5是不检验的,只有检验分段的MD5值
    分段上传时设置初始化的MD5值,最后合并段时并不会检验MD5值。分段上传过程中只能设置分段的MD5值,能否设置整个的MD5值保证合并段后检验呢。或者有什么接口能获取已上传文件的MD5值。
  • [调优工具] 性能分析工具进行java性能分析时,部署Guardian失败
    成功安装性能分析工具后,无法安装Guardian:部署Guardian失败,在目标主机中执行部署脚本失败。
  • [对接入门] 【应用】如何制作lxc容器使用的java应用
    前提:您已经仔细阅读过软件二次开发指南,并且在本地有环境可以进行操作第一步:举例,将一个helloword打包成一个jar包,此步骤比较简单,不附截图第二步,修改制作应用的脚本内容,如build_appHelloWorld.sh,参考内容如下:注意点package字段,Architecture字段如果是64位的则填写arm64第三步:修改service文件,详细内容如下:图中选中部分java需要使用绝对路径(/xxx/xxx/java),或者需要在service里面设置environment第四步:执行脚本制作应用第五步:启动服务器上的docker第六步:生成ova文件第七步:在设备上安装ova应用并验证jar包正常运行容器内查看应用已经运行原创文章,转载请标明出处
  • [技术干货] 2020-12-01:java中,什么是安全点和安全区域?
    2020-12-01:java中,什么是安全点和安全区域?#福大大架构师每日一题#
总条数:2301 到第 页
上滑加载中