Beware of Collection.retainAll in Java! – What I learned today!



Beware of Collection.retainAll in Java! – What I learned today!

Yesterday I got a nasty bug! Basically, I observed that a map – which was populated with about 20 values (no significance of particular number here) on first access (in a static manner) – was missing most of those values when accessed later. Begun the debugging.. and finally the culprit was caught.


Read full article from Beware of Collection.retainAll in Java! – What I learned today!


8 Reasons to Use Kotlin Over Java for Android Development - DZone Java



8 Reasons to Use Kotlin Over Java for Android Development - DZone Java

It's about time that you reconsider Java as your go-to language for your Android-based projects. And, it's about time to switch over to Kotlin, the (not so) new support language for Android development. But, what's behind its surging popularity amongst developers? In other words, what are the biggest advantages of Kotlin over Java?

Why should you even consider trying it as an alternative to the sometimes problematic, yet familiar and reliable Java? Now, here are some of the best answers to your questions:


Read full article from 8 Reasons to Use Kotlin Over Java for Android Development - DZone Java


Eclipse Foundation Releases Photon



Eclipse Foundation Releases Photon

Eclipse Photon enables developers to sort library entries alphabetically in Package Explorer; to enable it, open Java > Appearance preference page, and check Sort library entries alphabetically in Package Explorer. The libraries will be presented as follows:


Read full article from Eclipse Foundation Releases Photon


Pending Pane Items



Pending Pane Items

"Pending Pane Items" were formerly referred to as "Preview Tabs"

When you open a new file by single-clicking in the Tree View, it will open in a new tab with an italic title. This indicates that the file is "pending". When a file is pending, it will be replaced by the next pending file that is opened. This allows you to click through a bunch of files to find something without having to go back and close them all.

You can confirm a pending file by doing any of the following:

  • Double-clicking the tab of the file
  • Double-clicking the file in the tree view
  • Editing the contents of the file
  • Saving the file

You can also open a file already confirmed by double-clicking it in the tree view instead of single-clicking it.


Read full article from Pending Pane Items


zhisheng



zhisheng

程序员的日常离不开日志,日志就好比是程序员的私人秘书,负责运行周期一切trace工作。优秀的日志实践能极大帮助程序员快速定位问题,减少在线错误报警。本文从日志书写时各方面来做阐述,依据日志推荐的日志等级,做相应优秀日志实践的推荐。


Read full article from zhisheng


How to Replace Rules in JUnit 5 - Code Affine



How to Replace Rules in JUnit 5 - Code Affine

The recently published JUnit 5 (aka JUnit Lambda) alpha release caught my interest, and while skimming through the documentation I noticed that rules are gone – as well as runners and class rules. According to the user guide, these partially competing concepts have been replaced by a single consistent extension model.

Over the years, Frank and I wrote several rules to help with recurring tasks like testing SWT UIs, ignoring tests in certain environments, registering (test) OSGi services, running tests in separate threads, and some more.

Therefore, I was particularly interested in what it would take to transform existing rules to the new concept so that they could run natively on JUnit 5. To explore the capabilities of extensions, I picked two rules with quite different characteristics and tried to migrate them to JUnit 5.


Read full article from How to Replace Rules in JUnit 5 - Code Affine


Shall I learn Kotlin or Golang? - Quora



Shall I learn Kotlin or Golang? - Quora

Why? Because as a programmer it is you responsibility to know many different languages. In this day and age on the JVM: Java, Kotlin, Ceylon, Groovy, Clojure, and JRuby. For native code: C, C++, Rust, Go, D, Haskell. For the browser: JavaScript, Elm. It is an ongoing process of learning new languages.


Read full article from Shall I learn Kotlin or Golang? - Quora


debugging - Eclipse - Unable to install breakpoint due to missing line number attributes - Stack Overflow



debugging - Eclipse - Unable to install breakpoint due to missing line number attributes - Stack Overflow

I tried almost every solution here and no luck. Did you try clicking "Don't tell me again"? After doing so I restarted my program and all was well. Eclipse hit my breakpoint as if nothing was wrong.

The root cause for me was Eclipse was trying to setup debugging for auto-generated Spring CGLIB proxy objects. Unless you need to debug something at that level you should ignore the issue.


Read full article from debugging - Eclipse - Unable to install breakpoint due to missing line number attributes - Stack Overflow


google/google-java-format: Reformats Java source code to comply with Google Java Style.



google/google-java-format: Reformats Java source code to comply with Google Java Style.

java -jar /path/to/google-java-format-1.6-all-deps.jar <options> [files...]  

The formatter can act on whole files, on limited lines (--lines), on specific offsets (--offset), passing through to standard-out (default) or altered in-place (--replace).

To reformat changed lines in a specific patch, use google-java-format-diff.py.

Note: There is no configurability as to the formatter's algorithm for formatting. This is a deliberate design decision to unify our code formatting on a single format.


Read full article from google/google-java-format: Reformats Java source code to comply with Google Java Style.


一次线上问题排查所引发的思考 | crossoverJie's Blog



一次线上问题排查所引发的思考 | crossoverJie's Blog

之前或多或少分享过一些内存模型对象创建之类的内容,其实大部分人看完都是懵懵懂懂,也不知道这些的实际意义。

直到有一天你会碰到线上奇奇怪怪的问题,如:

  • 线程执行一个任务迟迟没有返回,应用假死。
  • 接口响应缓慢,甚至请求超时。
  • CPU 高负载运行。

这类问题并不像一个空指针、数组越界这样明显好查,这时就需要刚才提到的内存模型、对象创建、线程等相关知识结合在一起来排查问题了。

正好这次借助之前的一次生产问题来聊聊如何排查和解决问题。

生产现象

首先看看问题的背景吧:

我这其实是一个定时任务,在固定的时间会开启 N 个线程并发的从 Redis 中获取数据进行运算。

业务逻辑非常简单,但应用一般涉及到多线程之后再简单的事情都要小心对待。


Read full article from 一次线上问题排查所引发的思考 | crossoverJie's Blog


大熊的技术轶事



大熊的技术轶事

在对项目进行性能检测的时候,发现热点代码是一件重要且很有意义的事情,我们可以通过性能检测的数据,比如火焰图,找到代码中应该要优化的点,及早发现代码的性能瓶颈。


从本文中你会了解到:async-profiler工具的安装及使用、如何生成火焰图、以及如何看火焰图。


Read full article from 大熊的技术轶事


浏览器数据库 IndexedDB 入门教程 - 阮一峰的网络日志



浏览器数据库 IndexedDB 入门教程 - 阮一峰的网络日志

随着浏览器的功能不断增强,越来越多的网站开始考虑,将大量数据储存在客户端,这样可以减少从服务器获取数据,直接从本地获取数据。

现有的浏览器数据储存方案,都不适合储存大量数据:Cookie 的大小不超过4KB,且每次请求都会发送回服务器;LocalStorage 在 2.5MB 到 10MB 之间(各家浏览器不同),而且不提供搜索功能,不能建立自定义的索引。所以,需要一种新的解决方案,这就是 IndexedDB 诞生的背景。

通俗地说,IndexedDB 就是浏览器提供的本地数据库,它可以被网页脚本创建和操作。IndexedDB 允许储存大量数据,提供查找接口,还能建立索引。这些都是 LocalStorage 所不具备的。就数据库类型而言,IndexedDB 不属于关系型数据库(不支持 SQL 查询语句),更接近 NoSQL 数据库。

IndexedDB 具有以下特点。

(1)键值对储存。 IndexedDB 内部采用对象仓库(object store)存放数据。所有类型的数据都可以直接存入,包括 JavaScript 对象。对象仓库中,数据以"键值对"的形式保存,每一个数据记录都有对应的主键,主键是独一无二的,不能有重复,否则会抛出一个错误。

(2)异步。 IndexedDB 操作时不会锁死浏览器,用户依然可以进行其他操作,这与 LocalStorage 形成对比,后者的操作是同步的。异步设计是为了防止大量数据的读写,拖慢网页的表现。

(3)支持事务。 IndexedDB 支持事务(transaction),这意味着一系列操作步骤之中,只要有一步失败,整个事务就都取消,数据库回滚到事务发生之前的状态,不存在只改写一部分数据的情况。

(4)同源限制 IndexedDB 受到同源限制,每一个数据库对应创建它的域名。网页只能访问自身域名下的数据库,而不能访问跨域的数据库。


Read full article from 浏览器数据库 IndexedDB 入门教程 - 阮一峰的网络日志


[SOLR-8619] A new replica should not become leader when all current replicas are down as it leads to data loss - ASF JIRA



[SOLR-8619] A new replica should not become leader when all current replicas are down as it leads to data loss - ASF JIRA

Here's what I'm talking about:

  • Start a 2 node solrcloud cluster
  • Create a 1 shard/1 replica collection
  • Add documents
  • Shut down the node that has the only active shard
  • ADDREPLICA for the shard/collection, so Solr would attempt to add a new replica on the other node
  • Solr waits for a while before this replica becomes an active leader.
  • Index a few new docs
  • Bring up the old node
  • The replica comes up, with it's old index and then syncs to only contain the docs from the new leader.
    All old documents are lost in this case

Here are a few things that might work here:
1. Reject an ADDREPLICA call if all current replicas for the shard are down. Considering the new replica can not sync from anyone, it doesn't make sense for this replica to even come up
2. The replica shouldn't become active/leader unless either it was the last known leader or active before it went into recovering state
unless there are no other replicas in the clusterstate.


Read full article from [SOLR-8619] A new replica should not become leader when all current replicas are down as it leads to data loss - ASF JIRA


虚幻: 2017年十大亏损股之七——航美传媒AMCN 成本价2.72美元,2017年底1.15美元,持仓7000股,亏损比例约为57.72% 买入理由: 又是中概念股回归的坑... - 雪球



虚幻: 2017年十大亏损股之七——航美传媒AMCN 成本价2.72美元,2017年底1.15美元,持仓7000股,亏损比例约为57.72% 买入理由: 又是中概念股回归的坑... - 雪球

又是中概念股回归的坑这家公司主要做机场和航空广告要转型做飞机和铁路等长途旅行的Wifi接入服务私有化价格6美元后下调至4.1美元公司无负债主业的75%股权以21亿元卖出估值28亿这部分钱到帐后市值已经低于净现金值而且收购方还交了保证金应该说私有化的诚意满满的

2017年情况如下

私有化经过几次延期最后宣布取消应该还是航美wifi业务推进不顺利国内的资金没有兴趣最后没人投钱帮他们搞私有化管理层/公司在市场上的信誉尽失各路套利资金纷纷出逃股价跌破1元

2018年计划持有观察

公司转型据说是太过着急贸然地在产品体验很差的情况下大面积铺设wifi设备只见烧钱不见盈利窟窿越烧越大但航美最坏的时候也就如此了毕竟飞机/交通wifi还是有市场的痛点很明显有着明显的入口垄断效应也就说公司手里还是有牌的看是国内资本不看好融不到资只好把现金牛卖了


Read full article from 虚幻: 2017年十大亏损股之七——航美传媒AMCN 成本价2.72美元,2017年底1.15美元,持仓7000股,亏损比例约为57.72% 买入理由: 又是中概念股回归的坑... - 雪球


A Talk About Naming Things – mheap



A Talk About Naming Things – mheap

When the section on interfaces came up I knew what was coming. I'm totally sold on this already. It doesn't matter that you're working with an interface. All that matters is that you're working with an object with certain public methods available. How it accomplishes the task is nothing to do with you – so long as your collaborator respects your contract (and you respect it's public API e.g. don't call public methods that aren't in the interface) then everyone's happy.

Instead of adding Interface to differentiate your interface from your implementation, make your implementation more specificPaymentProcessor and PaymentProcessorInterface doesn't tell me anything. StripePaymentProcessor and PaymentProcessor lets me infer that we're processing payments via Stripe


Read full article from A Talk About Naming Things – mheap


Really simple SSH proxy (SOCKS5) | Thomas Hunter II



Really simple SSH proxy (SOCKS5) | Thomas Hunter II

SOCKS5 is a simple, eloquent method for getting yourself a proxified connection to the internet. All you need to get a proxy connection working is to run an SSH server somewhere, run a single command locally, and configure your software (or OS) to use this proxy. Why would you want to run a proxy? Well, all traffic sent between your client machine (e.g. a wireless laptop at a coffee shop), and the remote machine (e.g. your home server located on your trusted network) will be encrypted. Also, your external IP address will be that of the SSH server, which can be useful for various other reasons.

For this tutorial I will show screenshots for setting up an OS level proxy in OS X. Linux should have some similar GUI tools involved, or you can always configure it on the command line. I'm not sure if Windows has similar tools. I'm assuming you are familiar with networking basics and have a linux server setup with internet connectivity.

The first thing you will need to do is install an SSH daemon on your Linux server. Depending on your OS, it is usually as simple as running the following command (most distro's allow all normal users SSH access by default, save for the root user).


Read full article from Really simple SSH proxy (SOCKS5) | Thomas Hunter II


I Still Prefer Eclipse Over IntelliJ IDEA - Bozho's tech blog



I Still Prefer Eclipse Over IntelliJ IDEA - Bozho's tech blog

Over the years I've observed an inevitable shift from Eclipse to IntelliJ IDEA. Last year they were almost equal in usage, and I have the feeling things are swaying even more towards IDEA.

IDEA is like the iPhone of IDEs – its users tell you that "you will feel how much better it is once you get used to it", "are you STILL using Eclipse??", "IDEA is so much better, I thought everyone has switched", etc.

I've been using mostly Eclipse for the past 12 years, but in some cases I did use IDEA – when I was writing Scala, when I was writing Android, and most recently – when Eclipse failed to be ready for the Java 9 release, so after half a day of trying to get it working, I just switched to IDEA until Eclipse finally gets a working Java 9 version (with Maven and the rest of the stuff).

But I will get back to Eclipse again, soon. And I still prefer it. Not just because of all the key combinations I've internalized (you can reuse those in IDEA), but because there are still things I find worse in IDEA. Of course, IDEA has so much more cool features like code improvement suggestions and actually working plugins for everything. But at least some of the problems I see have to do with the more basic development workflow and experience. And you can't compensate for those with sugarcoating. So here they are:


Read full article from I Still Prefer Eclipse Over IntelliJ IDEA - Bozho's tech blog


Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts