Solyanka

    Recently, several different thoughts have accumulated. I hope some of them seem interesting.
    So, in a hodgepodge:

    1. Java: what is it ThreadLocal and InheritableThreadLocal
    2. Palm Pre: personal impressions
    3. Android: how to deploy the server on the phone
    4. Interfaces: the concept of the page about us
    5. Books: impressions of Pragmatic Thinking and Learning: Refactor Your wetware



    1. Java: what is ThreadLocal andInheritableThreadLocal


    Static variables in Java are global. All but 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, say: " Global.threadLocal.set("Thread1")". In thread 2 we ask: " Global.threadLocal.get()". And we will return the default value, not "Thread1".
    InheritableThreadLocalexpands 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, it 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()class function InheritableThreadLocal. It is called exactly when a new thread is created.

    2. Palm Pre: personal impressions


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

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


    On Android, it turns out you can deploy the server. Just one or two. ServerSocket is
    well supported there . 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 machine, you must enable port forwarding. To do this, I must say adb forward tcp:12345 tcp:54321where 12345 is the port on which the server socket on the phone hangs, and 54321 is the port of the local machine.
    It's amazing that everything just works out of the box on both the emulator and real devices.

    Perhaps, it is worth warning developers about the neat closure of sockets, it Socket::isClosed()does not always adequately express the state of the connection.

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


    Here's an idea: on the page "about us" put a common photo of all developers. You drag the mouse over the face of the developer, and information on what the person was doing appears on the left. Well, maybe a form for sending 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 should develop not only the "software" of the brain, but also the "hardware" ("wetware", in the case of people). Constantly learn, change areas, remember new information, do not be lazy to be curious. These activities will help the brain not stop creating new neural connections and change existing ones.
    Moreover, the author promotes an interesting thesis: develop the brain may not stop at a certain age. That is, if desired, with age, you can not lose the sharpness of thinking and the ability to learn new things. On the contrary, it is possible to develop the brain so that it will effectively absorb and process information.
    Highly Recommended: Pragmatic Thinking and Learning: Refactor Your Wetware .

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

    Also popular now: