java

java8 异步api、循环、日期

雨燕双飞 提交于 2021-02-18 08:03:44
java8 异步api、循环、日期 转载请注明出处: https://www.cnblogs.com/funnyzpc/p/10801470.html 异步api 对于多任务耗时的业务场景,一般我们会用到线程异步处理,在以前我们用 Thread 或者 Runnable 来实现异步,这是oracle官方做法,不过缺点很明显 对于复杂业务场景需要配置线程池 代码繁杂,对于新手容易造成不必要的bug 如果涉及到线程锁或线程通讯就棘手了 现在,java8为我们提供了 CompletableFuture 类,可以完全解决以上问题。 主要方法有: runAsync() 异步无参返回 样例: @Test public void asyncThread()throws Exception{ CompletableFuture async1 = CompletableFuture.runAsync(()->{ try { Thread.sleep(1000); System.out.println(Thread.currentThread().getName()); System.out.println("none return Async"); }catch (Exception e){ e.printStackTrace(); } }); // 调用get()将等待异步逻辑处理完成 async1

Java多态的理解

北城以北 提交于 2021-02-18 08:00:24
什么是多态 面向对象的三大特性:封装、继承、多态。从一定角度来看,封装和继承几乎都是为多态而准备的。这是我们最后一个概念,也是最重要的知识点。 多态的定义:指允许不同类的对象对同一消息做出响应。即同一消息可以根据发送对象的不同而采用多种不同的行为方式。(发送消息就是函数调用)。 实现多态的技术称为:动态绑定(dynamic binding),是指在执行期间判断所引用对象的实际类型,根据其实际的类型调用其相应的方法。 多态的作用:消除类型之间的耦合关系。 现实中,关于多态的例子不胜枚举。比方说按下 F1 键这个动作,如果当前在 Flash 界面下弹出的就是 AS 3 的帮助文档;如果当前在 Word 下弹出的就是 Word 帮助;在 Windows 下弹出的就是 Windows 帮助和支持。同一个事件发生在不同的对象上会产生不同的结果。 多态存在的三个必要条件 1、要有继承;2、要有重写;3、父类引用指向子类对象。 上菜 public class A { public String show ( D obj ) { //方法一 return ( "A and D" ); } public String show ( A obj ) { //方法二 return ( "A and A" ); } static class B extends A { public String show

Python3网络爬虫(一):利用urllib进行简单的网页抓取

拈花ヽ惹草 提交于 2021-02-18 08:00:01
点击 蓝色字 免费订阅, 每天收到这样的好信息 前言 : 最近有不少粉丝关注本公众号。并且我已经 成功开通了流量主同时会赚一点点广告费,我打算每个月把这部分钱拿出来给大家买点书刊,算是给大家一点福利吧。大家想买什么书扫描下方的加他拉你加群。最后,非常感谢大家的关注。 运行平台:Windows Python版本:Python3.x IDE:Sublime text3 转载请注明作者和出处: http://blog.csdn.net/c406495762/article/details/58716886 一直想学习Python爬虫的知识,在网上搜索了一下,大部分都是基于Python2.x的。因此打算写一个Python3.x的爬虫笔记,以便后续回顾,欢迎一起交流、共同进步。 一、预备知识 1.Python3.x基础知识学习: 可以在通过如下方式进行学习: (1)廖雪峰Python3教程(文档): URL:http://www.liaoxuefeng.com/ (2)菜鸟教程Python3教程(文档): URL:http://www.runoob.com/python3/python3-tutorial.html (3)鱼C工作室Python教程(视频): 小甲鱼老师很厉害,讲课风格幽默诙谐,如果时间充裕可以考虑看视频。 URL:http://www.fishc.com/ 2.开发环境搭建

为什么企业不喜欢招聘培训机构毕业的Tester(深度长文~)

孤街醉人 提交于 2021-02-18 07:59:42
现在,像达内、51testing、**、等等软件测试培训机构很多( 全国软件测试培训机构名单,回复6161获取 )~ 多数都是一些尚未毕业的大学生、毕业了一时找不到工作的大学生、 工作后想转行的再就业者,他们都希望通过三个月或半年或更久的培训,掌握某种技能,进入软件测试职业~ 然而事实真的像他们想象的那样吗? 多数情况并不像 培训机构的销售代表频频给你宣传的那样。 有的机构会推荐你就业直到你彻底失望他们推荐的单位,有的机构会放你出去闯荡江湖四处碰壁... 很多单位歧视培训机构毕业的学员,你所在的单位是这样吗?或者你从 IT 培训机构毕业后,找工作时被鄙视了吗? 为了弄明白为什么培训机构出来的Tester在找工作时经常遭遇不平等对待,我们需要弄明白“教育”和“培训”的差别。 Tester需要的特殊能力 成为一个合格的Tester,需要以下“特殊”能力: 延伸阅读: Tester 之 必备能力! 自知之明 自我学习 努力 看起来没什么出奇之处,也许你会觉得一个Tester最重要的能力不是上面三项~ Tester职业是一个入门简单,深入难的职业,是一个终身学习的职业;企业非常看重的是你的学习成长能力、培养潜力~ 具体可以看老徐之前的一篇文章: 测试老鸟告诉你:为什么多数企业不愿意招聘培训出来的学员? / 1 / 自知之明 我们要了解自己拥有什么、缺乏什么,然后才能开始学习。

eclipse自动添加注释

試著忘記壹切 提交于 2021-02-18 07:58:03
java类注释: 在新建类访问修饰符如public等前按住alt+shift+j出来注释 方法注释同上 method body是在方法内部添加注释(实现接口的时候自动添加) 重写的时候自动添加用overriding methods 新建文件时类注释 效果 来源: oschina 链接: https://my.oschina.net/u/4280283/blog/3895084

How to create a fat jar?

风流意气都作罢 提交于 2021-02-18 07:57:50
问题 With SpringBoot, you have the @SpringBootApplication annotation, but what is the equivalent with the neat Java Spark framework? IntelliJ creates a Maven project and I added the spark dependency, but running the install goal, I get a 5 KB jar with no manifest. Not an executable jar. The pom.xml created thus far is as follows: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:/

encrypt and encode URL parameters spring mvc

送分小仙女□ 提交于 2021-02-18 07:57:08
问题 I am writing a Spring mvc app and it needs to send an email with a link and encrypted params. The user will click on the link and I need to decrypt the params in the new page. So I am writing a util class to encrypt and decrypt along with encoding and decoding the parameters. When I run my stand alone java class(using for testing) - I get the following error when the decryption is called(encrypting, encoding, decoding works fine). java.security.InvalidAlgorithmParameterException: Wrong IV

MySQL Workbench 6.0 error could not acquire managemant access for the administrator?

不打扰是莪最后的温柔 提交于 2021-02-18 07:57:07
问题 I am using MySQL Workbench 6.0 over here. When I select the server status, I am getting this error Regarding this, I tried looking for solutions on Google and StackOverflow ( e.g. this result ) But here in MySQL Workbench 6.0, I don't know where is Server Administration of Mysql's and Workbench Central . Can anyone help me regarding this issue in MySQL Workbench 6.0? 回答1: Try running chcp in a terminal window (command line window). Does it run there? It should print out the current code page.

Dynamically calling a class method in java?

北战南征 提交于 2021-02-18 07:45:36
问题 Is it possible to dynamically call a method on a class from java? E.g, lets say I have the reference to a class, e.g either the string: 'com.foo.Bar', or com.foo.Bar.class , or anything else which is needed..). And I have an array / list of strings, e.g [First, Last, Email] . I want to simply loop through this array, and call the method 'validate' + element on the class that I have a reference to. E.g: MyInterface item = //instantiate the com.foo.Bar class here somehow, I'm not sure how. item

Allocation of space for local variables in loops

对着背影说爱祢 提交于 2021-02-18 07:41:44
问题 (true or false) The space for a local variable that is declared in the body of the loop is allocated whenever the loop body is executed and deallocated when the body finishes. The answer to this question is false. But why? 回答1: The statement is false because local variable space is not allocated and deallocated. It exists on the stack and is reserved when the method is entered. To see how stack space is used, write a small test program with: public static void test() { { int a = 1; long b = 2