📜 ⬆️ ⬇️

Solyanka

Over the last few years have accumulated several different thoughts. I hope some of them seem interesting.
So, in the hodgepodge:

1. Java: What are ThreadLocal and InheritableThreadLocal
2. Palm Pre: personal experiences
3. Android: how to deploy a server on the phone
4. Interfaces: the concept of the page "about us"
5. Books: Pragmatic Thinking and Learning Impressions: Refactor Your Wetware


')

1. Java: What are ThreadLocal and InheritableThreadLocal


Static variables in Java are global. All, except for one: ThreadLocal. ThreadLocal is a container in which you can put a value specific to the current thread.
For example, suppose we have a static variable Global.threadLocal . In thread 1, we say: " Global.threadLocal.set("Thread1") ". In thread 2 we ask: " Global.threadLocal.get() ". And we will return the default value, not "Thread1".
InheritableThreadLocal extends the concept. It saves the values ​​set in the thread from which the current one started. If thread 2 were created from thread 1, then Global.inheritableThreadLocal.get() in thread 2 would return the value from thread 1.

Bonus: if you need to build a tree of threads (who created whom), then you can overload the childValue() function of the InheritableThreadLocal class. It is called exactly when creating a new thread.

2. Palm Pre: personal experiences


Palm pre Not long ago, I managed to work with the Palm Pre . Palm Pre is a new phone from Palm. iPhone killer. In fact, the phone was very good. Firstly, a well-made operating system: a very nice interface, especially pleases correctly implemented multi-touch. Secondly, an excellent set of tools for the developer. For those who want to integrate deeply with the system (at the OS level), an SDK and a set of headers are provided. For developers, ordinary apps are a good set of tools and an emulator. Applications are a rather interesting hybrid of web applications and native methods. The platform is very developer-friendly.
They say that everyone in Palm is very proud of the product. From my point of view, there is something to be proud of.

3. Android: how to deploy a server on the phone


On Android, it turns out, you can deploy the server. Just once or twice.
There ServerSocket is perfectly supported. That is, you can create a thread with something like this:
while ( isRunning )
{
//
final Socket socket = serverSocket.accept();

// ! ?
if ( socket != null && socket.isConnected() )
{
//
}
}


* This source code was highlighted with Source Code Highlighter .


In order for this to work on a local typewriter, it is necessary to turn on port forwarding. For this, you need to say adb forward tcp:12345 tcp:54321 , where 12345 is the port on which the server socket is hanging on the phone, and 54321 is the port of the local machine.
It's amazing that everything just works out of the box and on the emulator, and on real devices.

Perhaps, it is worthwhile only to warn developers about the careful closure of sockets, Socket::isClosed() does not always adequately express the connection state.

4. Interfaces: the concept of the page "about us"


This is the idea: on the “about us” page, place a general photo of all developers. You circle the developer’s face with the mouse, and on the left, information appears about what the person was doing. Well, maybe a form to send a message. Something like this:
About Us

5. Books: Pragmatic Thinking and Learning Impressions: Refactor Your Wetware


The main idea of ​​the book: those who are engaged in mental work must develop not only the “software” of the brain, but also the “hardware” (“wetware”, in the case of humans). Constantly study, change spheres of activity, memorize new information, do not be lazy to be curious. These activities will help the brain to continue to create new neural connections and change existing ones.
Moreover, the author promotes an interesting thesis: the development of the brain may not cease at a certain age. That is, if you wish, with age you can not lose the severity of thinking and the ability to learn new things. On the contrary, you can develop the brain so that it will effectively assimilate and process information.
Highly recommend: Pragmatic Thinking and Learning: Refactor Your Wetware .

I hope there were enough smoked meats in my hodgepodge, and the reader enjoyed it.

Source: https://habr.com/ru/post/61388/


All Articles