java

lmax disruptor is too slow in multi-producer mode compared to single-producer mode

隐身守侯 提交于 2021-02-19 02:41:30
问题 Previously, when I use single-producer mode of disruptor, e.g. new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, 2048, moranContext.getThreadPoolExecutor(), ProducerType.Single, new BlockingWaitStrategy()) the performance is good. Now I am in a situation that multiple threads would write to a single ring buffer. What I found is that ProducerType.Multi make the code several times slower than single producer mode. That poor performance is not going to be accepted by me. So should I use single

Xpath to get the 2nd url with the matching text in the href tag

泄露秘密 提交于 2021-02-19 02:41:06
问题 A html page has paging links, 1 set at the top of the page and another on the bottom of the page. Using HtmlUnit, I am currently getting the HtmlAnchor on the page using getByAnchorText("1"); There is a problem in some of the links on the top, so I want to reference the bottom links using XPath. nextPageAnchor = (HtmlAnchor) page.getByXPath(""); How can I reference the 2nd link on the page, with using xpath? I need to reference the link using the AnchorText, so a link like: <a href="....">33<

How to make java class thread safe?

寵の児 提交于 2021-02-19 02:37:14
问题 I have a java class as below class User { String name; String phone; public String getName() { return name; } public String getPhone() { return phone; } } The way this class is used is, for every thread 1 object of this User class is created. Now since there is one copy of object for every thread, can i call this class as thread safe? Do I need to synchronize these methods? 回答1: The way you presented it, if each thread has its one copy, then it can be called thread-safe, as maximum of

Redirect all network of Android App (which is using Libraries) through a proxy network (if available)

偶尔善良 提交于 2021-02-19 02:35:08
问题 I am working on an Android application and I am using various libraries like Picaso, Retrofit, Crashlytics, etc. and my college WIFI have proxy on it. I know how to use a proxy when sending a HTTP requests to a server, but all the libraries that I am using have there own HTTP requests, so overriding all their HTTP classes would be a headache, and I am not even sure how to do that. So, is there a way to route all the traffic of the App through a proxy (when available), like any library or some

android --------System.err: java.net.UnknownServiceException: CLEARTEXT .....

余生长醉 提交于 2021-02-19 02:28:30
1,当调用远程接口进行网络通信时,报如下错误: W/ System.err: java.net.UnknownServiceException: CLEARTEXT communication to 10.240.35.113 not permitted by network security policy 这是因为新的保护机制对于仅使用安全通信的应用,Android 6.0 Marshmallow(API 级别 23)引入了两种机制来解决回退到明文通信的问题:(1) 在生产/安装库中,禁止明文通信,以及 (2) 在开发/QA 期间,在遇到任何非 TLS/SSL 通信时,予以记录或者触发崩溃。下文将更详细地介绍这两种机制。 2,解决方法: 如果一定要使用明文通信的话,则可以打开AndroidManifest.xml 文件,在 application 元素中添加: android:usesCleartextTraffic=” true ” 备注: 1)为了安全,不建议上面的使用明文的通信方式,不过上面的这种方法可以作为一种临时的通信策略 2)如果声明不使用明文通信,则可以在application元素中添加: android:usesCleartextTraffic=” false ” 此声明指示该应用不使用明文网络通信,并使 Android Marshmallow

工作10年后,再看String s = new String("xyz") 创建了几个对象?

梦想的初衷 提交于 2021-02-19 02:28:03
点击上方 " 程序员小乐 "关注, 星标或置顶一起成长 后台回复“ 大礼包 ”有惊喜礼包! 关注订阅号「 程序员小乐 」,收看更多精彩内容 每日英文 When a person cannot answer directly to ur question, probably the answer is too painful for you to know or too hard for them to admit. 如果一个人不正面回答你的问题,可能是说出来你难以接受,或者他们不愿意承认。 每日掏心话 一生中,最光辉的一天并非功成名就的那一天,而是从悲叹与绝望中产生对人生挑战与勇敢迈向意志的那一天。 来 自 :艾小仙 | 责编:乐乐 后端架构师(ID:study_tech) 第 1085 次推文 往日回顾: 2020 中国软件 100 强,腾讯第二、阿里第三,他第一! 正文 这个问题相信每个学习java的同学都不陌生,作为一个经典的面试题,到现在工作这么多年了我真是认为挺操蛋的一个问题,在网上到现在你仍然可以看见很多讨论这个问题的人,其中不乏工作很多年的人都有争论,我认为还是有必要来说一说这个问题的。 从方法区说起 常量池存在于方法区,而方法区在jdk1.7版本前后改变比较大,所以还是先来说说方法区的演变。 在jdk1.7版本之前,常量池存在于方法区,方法区是堆的一个逻辑部分

how to 'Zero out' from memory an AES SecretKeySpec Key in Java

放肆的年华 提交于 2021-02-19 02:25:27
问题 I am using Java AES encryption using SecretKeySpec(byte[] key, String algorithm) to generate a Key object. After I encrypt something, I want to remove the Key from memory. I can remove all references to the Key, but that does not guarantee that the key is not floating somewhere in memory. I can "zero out" the byte[] array that I used to generate the Key, but how can I zero out or flush the actual Key memory. 回答1: There doesn't appear to be a way to do this in Java versions up to 7, but it has

Generating AutoCAD files with java?

情到浓时终转凉″ 提交于 2021-02-19 02:24:07
问题 Does anyone have any tips how I can generate AutoCAD drawings with Java? Is dfx a good interface or should we go for dwg files? I can't find any useful information on this on the net. The Open Design Alliance have libraries for generating dwg, but I can't look at the API without becoming a member. And they don't seem to have a java interface either. 回答1: If you don't have to generate dwg, and you can represent what you want in dxf then I suggest going with dxf. It is fairly easy to write dxf

Is it possible to open a .txt/.java file containing a class, and using reflection on it?

我们两清 提交于 2021-02-19 02:23:29
问题 What I mean by this, is opening a file with a Java code in it as a class, not as a file. So basically I want to: -> Open a pure text file in a self written Java application (.txt/.log/.java) -> Recognize class(es) in the file, for example: public class TestExample { private String example; public String getExample() { return example; } } I will open this in a hand-written program. Instead of recognizing the text in the file as a String or as pure text, it will find the class TestExample in it

Split a flux into two fluxes - head and tail

亡梦爱人 提交于 2021-02-19 02:18:37
问题 I want to split a flux into two fluxes where the first one has the first item of the original flux and the second one will takes the rest of items. After applying a custom transformation myLogic on each flux I want to combine them into one flux preserving the order of the original flux. Example: S: student S': student after applying myLogic Emitted flux: s1 -> s2 -> s3 -> s4 The first splited flux: s1' => myLogic The second splited flux: s2' -> s3' -> s4' => myLogic The combined flux: s1' ->